remove all uses of iota (#4046)
I've needed to catch gotchas that arise from contributors adding a value in the middle of an iota list, not to mention have dealt with prior bugs that happened the same way, now too many times to feel safe about its usage. This PR removes the use of iota from all const declarations. The intent is to not allow the use of iota within the codebase. --- #### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #3993 #### Test Plan - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
2c00ca40ac
commit
9abd9d4f96
@ -13,10 +13,10 @@ var ErrNotFound = clues.New("not found")
|
||||
type CollectionState int
|
||||
|
||||
const (
|
||||
NewState = CollectionState(iota)
|
||||
NotMovedState
|
||||
MovedState
|
||||
DeletedState
|
||||
NewState CollectionState = 0
|
||||
NotMovedState CollectionState = 1
|
||||
MovedState CollectionState = 2
|
||||
DeletedState CollectionState = 3
|
||||
)
|
||||
|
||||
type FetchRestoreCollection struct {
|
||||
|
||||
@ -31,13 +31,13 @@ type collectionScope int
|
||||
const (
|
||||
// CollectionScopeUnknown is used when we don't know and don't need
|
||||
// to know the kind, like in the case of deletes
|
||||
CollectionScopeUnknown collectionScope = iota
|
||||
CollectionScopeUnknown collectionScope = 0
|
||||
|
||||
// CollectionScopeFolder is used for regular folder collections
|
||||
CollectionScopeFolder
|
||||
CollectionScopeFolder collectionScope = 1
|
||||
|
||||
// CollectionScopePackage is used to represent OneNote items
|
||||
CollectionScopePackage
|
||||
CollectionScopePackage collectionScope = 2
|
||||
)
|
||||
|
||||
const restrictedDirectory = "Site Pages"
|
||||
|
||||
@ -14,8 +14,8 @@ import (
|
||||
type SharingMode int
|
||||
|
||||
const (
|
||||
SharingModeCustom = SharingMode(iota)
|
||||
SharingModeInherited
|
||||
SharingModeCustom SharingMode = 0
|
||||
SharingModeInherited SharingMode = 1
|
||||
)
|
||||
|
||||
type GV2Type string
|
||||
|
||||
@ -59,6 +59,7 @@ func CollectPages(
|
||||
bpc inject.BackupProducerConfig,
|
||||
creds account.M365Config,
|
||||
ac api.Client,
|
||||
scope selectors.SharePointScope,
|
||||
su support.StatusUpdater,
|
||||
errs *fault.Bus,
|
||||
) ([]data.BackupCollection, error) {
|
||||
@ -105,7 +106,7 @@ func CollectPages(
|
||||
collection := NewCollection(
|
||||
dir,
|
||||
ac,
|
||||
Pages,
|
||||
scope,
|
||||
su,
|
||||
bpc.Options)
|
||||
collection.SetBetaService(betaService)
|
||||
@ -122,6 +123,7 @@ func CollectLists(
|
||||
bpc inject.BackupProducerConfig,
|
||||
ac api.Client,
|
||||
tenantID string,
|
||||
scope selectors.SharePointScope,
|
||||
su support.StatusUpdater,
|
||||
errs *fault.Bus,
|
||||
) ([]data.BackupCollection, error) {
|
||||
@ -156,7 +158,7 @@ func CollectLists(
|
||||
collection := NewCollection(
|
||||
dir,
|
||||
ac,
|
||||
List,
|
||||
scope,
|
||||
su,
|
||||
bpc.Options)
|
||||
collection.AddJob(tuple.ID)
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/alcionai/corso/src/internal/version"
|
||||
"github.com/alcionai/corso/src/pkg/control"
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -61,11 +62,14 @@ func (suite *SharePointPagesSuite) TestCollectPages() {
|
||||
ProtectedResource: mock.NewProvider(siteID, siteID),
|
||||
}
|
||||
|
||||
sel := selectors.NewSharePointBackup([]string{siteID})
|
||||
|
||||
col, err := CollectPages(
|
||||
ctx,
|
||||
bpc,
|
||||
creds,
|
||||
ac,
|
||||
sel.Lists(selectors.Any())[0],
|
||||
(&MockGraphService{}).UpdateStatus,
|
||||
fault.New(true))
|
||||
assert.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
@ -21,19 +21,23 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/logger"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
type DataCategory int
|
||||
|
||||
// channel sizes
|
||||
const (
|
||||
collectionChannelBufferSize = 50
|
||||
fetchChannelSize = 5
|
||||
)
|
||||
|
||||
//go:generate stringer -type=DataCategory
|
||||
const (
|
||||
collectionChannelBufferSize = 50
|
||||
fetchChannelSize = 5
|
||||
Unknown DataCategory = iota
|
||||
List
|
||||
Drive
|
||||
Pages
|
||||
Unknown DataCategory = 0
|
||||
List DataCategory = 1
|
||||
Pages DataCategory = 2
|
||||
)
|
||||
|
||||
var (
|
||||
@ -53,7 +57,7 @@ type Collection struct {
|
||||
// jobs contain the SharePoint.Site.ListIDs for the associated list(s).
|
||||
jobs []string
|
||||
// M365 IDs of the items of this collection
|
||||
category DataCategory
|
||||
category path.CategoryType
|
||||
client api.Sites
|
||||
ctrl control.Options
|
||||
betaService *betaAPI.BetaService
|
||||
@ -64,7 +68,7 @@ type Collection struct {
|
||||
func NewCollection(
|
||||
folderPath path.Path,
|
||||
ac api.Client,
|
||||
category DataCategory,
|
||||
scope selectors.SharePointScope,
|
||||
statusUpdater support.StatusUpdater,
|
||||
ctrlOpts control.Options,
|
||||
) *Collection {
|
||||
@ -74,7 +78,7 @@ func NewCollection(
|
||||
data: make(chan data.Item, collectionChannelBufferSize),
|
||||
client: ac.Sites(),
|
||||
statusUpdater: statusUpdater,
|
||||
category: category,
|
||||
category: scope.Category().PathType(),
|
||||
ctrl: ctrlOpts,
|
||||
}
|
||||
|
||||
@ -198,9 +202,9 @@ func (sc *Collection) runPopulate(
|
||||
|
||||
// Switch retrieval function based on category
|
||||
switch sc.category {
|
||||
case List:
|
||||
case path.ListsCategory:
|
||||
metrics, err = sc.retrieveLists(ctx, writer, colProgress, errs)
|
||||
case Pages:
|
||||
case path.PagesCategory:
|
||||
metrics, err = sc.retrievePages(ctx, sc.client, writer, colProgress, errs)
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/control/testdata"
|
||||
"github.com/alcionai/corso/src/pkg/fault"
|
||||
"github.com/alcionai/corso/src/pkg/path"
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||
)
|
||||
|
||||
@ -82,16 +83,18 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
|
||||
dirRoot = "directory"
|
||||
)
|
||||
|
||||
sel := selectors.NewSharePointBackup([]string{"site"})
|
||||
|
||||
tables := []struct {
|
||||
name, itemName string
|
||||
category DataCategory
|
||||
scope selectors.SharePointScope
|
||||
getDir func(t *testing.T) path.Path
|
||||
getItem func(t *testing.T, itemName string) *Item
|
||||
}{
|
||||
{
|
||||
name: "List",
|
||||
itemName: "MockListing",
|
||||
category: List,
|
||||
scope: sel.Lists(selectors.Any())[0],
|
||||
getDir: func(t *testing.T) path.Path {
|
||||
dir, err := path.Build(
|
||||
tenant,
|
||||
@ -127,7 +130,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
|
||||
{
|
||||
name: "Pages",
|
||||
itemName: "MockPages",
|
||||
category: Pages,
|
||||
scope: sel.Pages(selectors.Any())[0],
|
||||
getDir: func(t *testing.T) path.Path {
|
||||
dir, err := path.Build(
|
||||
tenant,
|
||||
@ -166,7 +169,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
|
||||
col := NewCollection(
|
||||
test.getDir(t),
|
||||
suite.ac,
|
||||
test.category,
|
||||
test.scope,
|
||||
nil,
|
||||
control.DefaultOptions())
|
||||
col.data <- test.getItem(t, test.itemName)
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
// Code generated by "stringer -type=DataCategory"; DO NOT EDIT.
|
||||
|
||||
package site
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[Unknown-2]
|
||||
_ = x[List-3]
|
||||
_ = x[Drive-4]
|
||||
_ = x[Pages-5]
|
||||
}
|
||||
|
||||
const _DataCategory_name = "UnknownListDrivePages"
|
||||
|
||||
var _DataCategory_index = [...]uint8{0, 7, 11, 16, 21}
|
||||
|
||||
func (i DataCategory) String() string {
|
||||
i -= 2
|
||||
if i < 0 || i >= DataCategory(len(_DataCategory_index)-1) {
|
||||
return "DataCategory(" + strconv.FormatInt(int64(i+2), 10) + ")"
|
||||
}
|
||||
return _DataCategory_name[_DataCategory_index[i]:_DataCategory_index[i+1]]
|
||||
}
|
||||
@ -63,6 +63,7 @@ func ProduceBackupCollections(
|
||||
bpc,
|
||||
ac,
|
||||
creds.AzureTenantID,
|
||||
scope,
|
||||
su,
|
||||
errs)
|
||||
if err != nil {
|
||||
@ -95,6 +96,7 @@ func ProduceBackupCollections(
|
||||
bpc,
|
||||
creds,
|
||||
ac,
|
||||
scope,
|
||||
su,
|
||||
errs)
|
||||
if err != nil {
|
||||
|
||||
@ -37,10 +37,10 @@ type Operation int
|
||||
|
||||
//go:generate stringer -type=Operation
|
||||
const (
|
||||
OpUnknown Operation = iota
|
||||
Backup
|
||||
Restore
|
||||
Export
|
||||
OpUnknown Operation = 0
|
||||
Backup Operation = 1
|
||||
Restore Operation = 2
|
||||
Export Operation = 3
|
||||
)
|
||||
|
||||
// Constructor for ConnectorOperationStatus. If the counts do not agree, an error is returned.
|
||||
|
||||
@ -22,12 +22,12 @@ func (id StableID) String() string {
|
||||
//
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type=Schema
|
||||
const (
|
||||
UnknownSchema = Schema(iota)
|
||||
BackupOpSchema
|
||||
RestoreOpSchema
|
||||
BackupSchema
|
||||
BackupDetailsSchema
|
||||
RepositorySchema
|
||||
UnknownSchema Schema = 0
|
||||
BackupOpSchema Schema = 1
|
||||
RestoreOpSchema Schema = 2
|
||||
BackupSchema Schema = 3
|
||||
BackupDetailsSchema Schema = 4
|
||||
RepositorySchema Schema = 5
|
||||
)
|
||||
|
||||
// common tags for filtering
|
||||
@ -38,7 +38,7 @@ const (
|
||||
MergeBackup = "merge-backup"
|
||||
)
|
||||
|
||||
// Valid returns true if the ModelType value fits within the iota range.
|
||||
// Valid returns true if the ModelType value fits within the const range.
|
||||
func (mt Schema) Valid() bool {
|
||||
return mt > 0 && mt < RepositorySchema+1
|
||||
}
|
||||
|
||||
@ -33,11 +33,11 @@ type OpStatus int
|
||||
|
||||
//go:generate stringer -type=OpStatus -linecomment
|
||||
const (
|
||||
Unknown OpStatus = iota // Status Unknown
|
||||
InProgress // In Progress
|
||||
Completed // Completed
|
||||
Failed // Failed
|
||||
NoData // No Data
|
||||
Unknown OpStatus = 0 // Status Unknown
|
||||
InProgress OpStatus = 1 // In Progress
|
||||
Completed OpStatus = 2 // Completed
|
||||
Failed OpStatus = 3 // Failed
|
||||
NoData OpStatus = 4 // No Data
|
||||
)
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
@ -10,8 +10,8 @@ type accountProvider int
|
||||
|
||||
//go:generate stringer -type=accountProvider -linecomment
|
||||
const (
|
||||
ProviderUnknown accountProvider = iota // Unknown Provider
|
||||
ProviderM365 // M365
|
||||
ProviderUnknown accountProvider = 0 // Unknown Provider
|
||||
ProviderM365 accountProvider = 1 // M365
|
||||
)
|
||||
|
||||
// storage parsing errors
|
||||
|
||||
@ -20,16 +20,17 @@ type ItemType int
|
||||
// Additionally, any itemType directly assigned a number should not be altered.
|
||||
// This applies to OneDriveItem and FolderItem
|
||||
const (
|
||||
UnknownType ItemType = iota // 0, global unknown value
|
||||
UnknownType ItemType = 0
|
||||
|
||||
// Exchange (00x)
|
||||
ExchangeContact
|
||||
ExchangeEvent
|
||||
ExchangeMail
|
||||
ExchangeContact ItemType = 1
|
||||
ExchangeEvent ItemType = 2
|
||||
ExchangeMail ItemType = 3
|
||||
|
||||
// SharePoint (10x)
|
||||
SharePointLibrary ItemType = iota + 97 // 100
|
||||
SharePointList // 101...
|
||||
SharePointPage
|
||||
SharePointLibrary ItemType = 101
|
||||
SharePointList ItemType = 102
|
||||
SharePointPage ItemType = 103
|
||||
|
||||
// OneDrive (20x)
|
||||
OneDriveItem ItemType = 205
|
||||
|
||||
@ -25,12 +25,10 @@ type Maintenance struct {
|
||||
|
||||
type MaintenanceType int
|
||||
|
||||
// Can't be reordered as we rely on iota for numbering.
|
||||
//
|
||||
//go:generate stringer -type=MaintenanceType -linecomment
|
||||
const (
|
||||
CompleteMaintenance MaintenanceType = iota // complete
|
||||
MetadataMaintenance // metadata
|
||||
CompleteMaintenance MaintenanceType = 0 // complete
|
||||
MetadataMaintenance MaintenanceType = 1 // metadata
|
||||
)
|
||||
|
||||
var StringToMaintenanceType = map[string]MaintenanceType{
|
||||
@ -40,16 +38,14 @@ var StringToMaintenanceType = map[string]MaintenanceType{
|
||||
|
||||
type MaintenanceSafety int
|
||||
|
||||
// Can't be reordered as we rely on iota for numbering.
|
||||
//
|
||||
//go:generate stringer -type=MaintenanceSafety -linecomment
|
||||
const (
|
||||
FullMaintenanceSafety MaintenanceSafety = iota
|
||||
FullMaintenanceSafety MaintenanceSafety = 0
|
||||
//nolint:lll
|
||||
// Use only if there's no other kopia instances accessing the repo and the
|
||||
// storage backend is strongly consistent.
|
||||
// https://github.com/kopia/kopia/blob/f9de453efc198b6e993af8922f953a7e5322dc5f/repo/maintenance/maintenance_safety.go#L42
|
||||
NoMaintenanceSafety
|
||||
NoMaintenanceSafety MaintenanceSafety = 1
|
||||
)
|
||||
|
||||
type RetentionMode int
|
||||
|
||||
@ -17,15 +17,15 @@ type CategoryType int
|
||||
|
||||
//go:generate stringer -type=CategoryType -linecomment
|
||||
const (
|
||||
UnknownCategory CategoryType = iota
|
||||
EmailCategory // email
|
||||
ContactsCategory // contacts
|
||||
EventsCategory // events
|
||||
FilesCategory // files
|
||||
ListsCategory // lists
|
||||
LibrariesCategory // libraries
|
||||
PagesCategory // pages
|
||||
DetailsCategory // details
|
||||
UnknownCategory CategoryType = 0
|
||||
EmailCategory CategoryType = 1 // email
|
||||
ContactsCategory CategoryType = 2 // contacts
|
||||
EventsCategory CategoryType = 3 // events
|
||||
FilesCategory CategoryType = 4 // files
|
||||
ListsCategory CategoryType = 5 // lists
|
||||
LibrariesCategory CategoryType = 6 // libraries
|
||||
PagesCategory CategoryType = 7 // pages
|
||||
DetailsCategory CategoryType = 8 // details
|
||||
)
|
||||
|
||||
func ToCategoryType(category string) CategoryType {
|
||||
|
||||
@ -22,17 +22,17 @@ type ServiceType int
|
||||
|
||||
//go:generate stringer -type=ServiceType -linecomment
|
||||
const (
|
||||
UnknownService ServiceType = iota
|
||||
ExchangeService // exchange
|
||||
OneDriveService // onedrive
|
||||
SharePointService // sharepoint
|
||||
ExchangeMetadataService // exchangeMetadata
|
||||
OneDriveMetadataService // onedriveMetadata
|
||||
SharePointMetadataService // sharepointMetadata
|
||||
GroupsService // groups
|
||||
GroupsMetadataService // groupsMetadata
|
||||
TeamsService // teams
|
||||
TeamsMetadataService // teamsMetadata
|
||||
UnknownService ServiceType = 0
|
||||
ExchangeService ServiceType = 1 // exchange
|
||||
OneDriveService ServiceType = 2 // onedrive
|
||||
SharePointService ServiceType = 3 // sharepoint
|
||||
ExchangeMetadataService ServiceType = 4 // exchangeMetadata
|
||||
OneDriveMetadataService ServiceType = 5 // onedriveMetadata
|
||||
SharePointMetadataService ServiceType = 6 // sharepointMetadata
|
||||
GroupsService ServiceType = 7 // groups
|
||||
GroupsMetadataService ServiceType = 8 // groupsMetadata
|
||||
TeamsService ServiceType = 9 // teams
|
||||
TeamsMetadataService ServiceType = 10 // teamsMetadata
|
||||
)
|
||||
|
||||
func toServiceType(service string) ServiceType {
|
||||
@ -45,12 +45,20 @@ func toServiceType(service string) ServiceType {
|
||||
return OneDriveService
|
||||
case strings.ToLower(SharePointService.String()):
|
||||
return SharePointService
|
||||
case strings.ToLower(GroupsService.String()):
|
||||
return GroupsService
|
||||
case strings.ToLower(TeamsService.String()):
|
||||
return TeamsService
|
||||
case strings.ToLower(ExchangeMetadataService.String()):
|
||||
return ExchangeMetadataService
|
||||
case strings.ToLower(OneDriveMetadataService.String()):
|
||||
return OneDriveMetadataService
|
||||
case strings.ToLower(SharePointMetadataService.String()):
|
||||
return SharePointMetadataService
|
||||
case strings.ToLower(GroupsMetadataService.String()):
|
||||
return GroupsMetadataService
|
||||
case strings.ToLower(TeamsMetadataService.String()):
|
||||
return TeamsMetadataService
|
||||
default:
|
||||
return UnknownService
|
||||
}
|
||||
|
||||
@ -17,11 +17,13 @@ func _() {
|
||||
_ = x[SharePointMetadataService-6]
|
||||
_ = x[GroupsService-7]
|
||||
_ = x[GroupsMetadataService-8]
|
||||
_ = x[TeamsService-9]
|
||||
_ = x[TeamsMetadataService-10]
|
||||
}
|
||||
|
||||
const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadata"
|
||||
const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadatateamsteamsMetadata"
|
||||
|
||||
var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110}
|
||||
var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110, 115, 128}
|
||||
|
||||
func (i ServiceType) String() string {
|
||||
if i < 0 || i >= ServiceType(len(_ServiceType_index)-1) {
|
||||
|
||||
@ -20,11 +20,11 @@ type service int
|
||||
|
||||
//go:generate stringer -type=service -linecomment
|
||||
const (
|
||||
ServiceUnknown service = iota // Unknown Service
|
||||
ServiceExchange // Exchange
|
||||
ServiceOneDrive // OneDrive
|
||||
ServiceSharePoint // SharePoint
|
||||
ServiceGroups // Groups
|
||||
ServiceUnknown service = 0 // Unknown Service
|
||||
ServiceExchange service = 1 // Exchange
|
||||
ServiceOneDrive service = 2 // OneDrive
|
||||
ServiceSharePoint service = 3 // SharePoint
|
||||
ServiceGroups service = 4 // Groups
|
||||
)
|
||||
|
||||
var serviceToPathType = map[service]path.ServiceType{
|
||||
|
||||
@ -12,8 +12,8 @@ type storageProvider int
|
||||
|
||||
//go:generate stringer -type=storageProvider -linecomment
|
||||
const (
|
||||
ProviderUnknown storageProvider = iota // Unknown Provider
|
||||
ProviderS3 // S3
|
||||
ProviderUnknown storageProvider = 0 // Unknown Provider
|
||||
ProviderS3 storageProvider = 1 // S3
|
||||
)
|
||||
|
||||
// storage parsing errors
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user