diff --git a/src/internal/connector/exchange/exchange_service_test.go b/src/internal/connector/exchange/exchange_service_test.go index 25dc25123..d2ae66fa4 100644 --- a/src/internal/connector/exchange/exchange_service_test.go +++ b/src/internal/connector/exchange/exchange_service_test.go @@ -12,6 +12,7 @@ import ( "github.com/alcionai/corso/internal/common" "github.com/alcionai/corso/internal/connector/graph" "github.com/alcionai/corso/internal/connector/mockconnector" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/internal/tester" "github.com/alcionai/corso/pkg/account" "github.com/alcionai/corso/pkg/control" @@ -457,37 +458,37 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() { func (suite *ExchangeServiceSuite) TestGetRestoreContainer() { tests := []struct { name string - option string + option path.CategoryType checkError assert.ErrorAssertionFunc cleanupFunc func(graph.Service, string, string) error }{ { name: "Establish User Restore Folder", - option: "users", + option: path.CategoryType(-1), checkError: assert.Error, cleanupFunc: nil, }, { name: "Establish Event Restore Location", - option: "events", + option: path.EventsCategory, checkError: assert.NoError, cleanupFunc: DeleteCalendar, }, { name: "Establish Restore Folder for Unknown", - option: "unknown", + option: path.UnknownCategory, checkError: assert.Error, cleanupFunc: nil, }, { name: "Establish Restore folder for Mail", - option: "mail", + option: path.EmailCategory, checkError: assert.NoError, cleanupFunc: DeleteMailFolder, }, { name: "Establish Restore folder for Contacts", - option: "contacts", + option: path.ContactsCategory, checkError: assert.NoError, cleanupFunc: DeleteContactFolder, }, diff --git a/src/internal/connector/exchange/query_options.go b/src/internal/connector/exchange/query_options.go index 126618392..9e38c19be 100644 --- a/src/internal/connector/exchange/query_options.go +++ b/src/internal/connector/exchange/query_options.go @@ -13,6 +13,8 @@ import ( msmessage "github.com/microsoftgraph/msgraph-sdk-go/users/item/messages" msitem "github.com/microsoftgraph/msgraph-sdk-go/users/item/messages/item" "github.com/pkg/errors" + + "github.com/alcionai/corso/internal/path" ) //----------------------------------------------------------------------- @@ -99,19 +101,13 @@ const ( contacts ) -const ( - mailCategory = "mail" - contactsCategory = "contacts" - eventsCategory = "events" -) - -func categoryToOptionIdentifier(category string) optionIdentifier { +func categoryToOptionIdentifier(category path.CategoryType) optionIdentifier { switch category { - case mailCategory: + case path.EmailCategory: return messages - case contactsCategory: + case path.ContactsCategory: return contacts - case eventsCategory: + case path.EventsCategory: return events default: return unknown diff --git a/src/internal/connector/exchange/service_functions.go b/src/internal/connector/exchange/service_functions.go index e13002f93..2150f22d6 100644 --- a/src/internal/connector/exchange/service_functions.go +++ b/src/internal/connector/exchange/service_functions.go @@ -14,6 +14,7 @@ import ( "github.com/alcionai/corso/internal/common" "github.com/alcionai/corso/internal/connector/graph" "github.com/alcionai/corso/internal/connector/support" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/pkg/account" "github.com/alcionai/corso/pkg/control" "github.com/alcionai/corso/pkg/logger" @@ -302,7 +303,8 @@ func SetupExchangeCollectionVars(scope selectors.ExchangeScope) ( // that defines the application the folder is created in. func GetRestoreContainer( service graph.Service, - user, category string, + user string, + category path.CategoryType, ) (string, error) { name := fmt.Sprintf("Corso_Restore_%s", common.FormatNow(common.SimpleDateTimeFormat)) option := categoryToOptionIdentifier(category) @@ -346,7 +348,7 @@ func GetRestoreContainer( func RestoreExchangeObject( ctx context.Context, bits []byte, - category string, + category path.CategoryType, policy control.CollisionPolicy, service graph.Service, destination, user string, @@ -354,7 +356,7 @@ func RestoreExchangeObject( var setting optionIdentifier switch category { - case mailCategory, contactsCategory: + case path.EmailCategory, path.ContactsCategory: setting = categoryToOptionIdentifier(category) default: return fmt.Errorf("type: %s not supported for exchange restore", category) diff --git a/src/internal/connector/exchange/service_iterators.go b/src/internal/connector/exchange/service_iterators.go index 91434aee4..13aa95d3e 100644 --- a/src/internal/connector/exchange/service_iterators.go +++ b/src/internal/connector/exchange/service_iterators.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/internal/connector/graph" "github.com/alcionai/corso/internal/connector/support" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/pkg/selectors" ) @@ -50,7 +51,7 @@ func IterateSelectAllDescendablesForCollections( var ( isCategorySet bool collectionType optionIdentifier - category string + category path.CategoryType ) return func(pageItem any) bool { @@ -58,12 +59,12 @@ func IterateSelectAllDescendablesForCollections( if !isCategorySet { if qp.Scope.IncludesCategory(selectors.ExchangeMail) { collectionType = messages - category = mailCategory + category = path.EmailCategory } if qp.Scope.IncludesCategory(selectors.ExchangeContact) { collectionType = contacts - category = contactsCategory + category = path.ContactsCategory } isCategorySet = true @@ -85,7 +86,7 @@ func IterateSelectAllDescendablesForCollections( edc := NewCollection( qp.User, - []string{qp.Credentials.TenantID, qp.User, category, directory}, + []string{qp.Credentials.TenantID, qp.User, category.String(), directory}, collectionType, service, statusUpdater, @@ -167,7 +168,7 @@ func IterateSelectAllEventsForCollections( edc := NewCollection( qp.User, - []string{qp.Credentials.TenantID, qp.User, eventsCategory, directory}, + []string{qp.Credentials.TenantID, qp.User, path.EventsCategory.String(), directory}, events, service, statusUpdater, @@ -276,7 +277,7 @@ func IterateFilterFolderDirectoriesForCollections( temp := NewCollection( qp.User, - []string{qp.Credentials.TenantID, qp.User, mailCategory, directory}, + []string{qp.Credentials.TenantID, qp.User, path.EmailCategory.String(), directory}, messages, service, statusUpdater, diff --git a/src/internal/connector/graph_connector.go b/src/internal/connector/graph_connector.go index 41e851426..ab578b79c 100644 --- a/src/internal/connector/graph_connector.go +++ b/src/internal/connector/graph_connector.go @@ -18,6 +18,7 @@ import ( "github.com/alcionai/corso/internal/connector/graph" "github.com/alcionai/corso/internal/connector/support" "github.com/alcionai/corso/internal/data" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/pkg/account" "github.com/alcionai/corso/pkg/control" "github.com/alcionai/corso/pkg/selectors" @@ -260,8 +261,9 @@ func (gc *GraphConnector) RestoreExchangeDataCollection( directory = strings.Join(dc.FullPath(), "") user = dc.FullPath()[1] items = dc.Items() - category = dc.FullPath()[2] - exit bool + // TODO(ashmrtn): Update this when we have path struct support in collections. + category = path.ToCategoryType(dc.FullPath()[2]) + exit bool ) if _, ok := pathCounter[directory]; !ok { diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index d1c952bfc..557b79b46 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -17,6 +17,7 @@ import ( "github.com/alcionai/corso/internal/connector/mockconnector" "github.com/alcionai/corso/internal/connector/support" "github.com/alcionai/corso/internal/data" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/internal/tester" "github.com/alcionai/corso/pkg/selectors" ) @@ -245,13 +246,13 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression() // The result should be all successful items restored within the same folder. func (suite *GraphConnectorIntegrationSuite) TestRestoreMessages() { t := suite.T() - category := "mail" + category := path.EmailCategory connector := loadConnector(t) collection := make([]data.Collection, 0) for i := 0; i < 3; i++ { mdc := mockconnector.NewMockExchangeCollection( - []string{"tenant", suite.user, category, "Inbox"}, + []string{"tenant", suite.user, category.String(), "Inbox"}, 1) collection = append(collection, mdc) } diff --git a/src/internal/kopia/model_store_test.go b/src/internal/kopia/model_store_test.go index 852644983..75145a124 100644 --- a/src/internal/kopia/model_store_test.go +++ b/src/internal/kopia/model_store_test.go @@ -566,7 +566,7 @@ func (suite *ModelStoreRegressionSuite) TestMultipleConfigs() { deets.Entries = append( deets.Entries, details.DetailsEntry{ - RepoRef: fmt.Sprintf("exchange/user1/mail/inbox/mail%v", i), + RepoRef: fmt.Sprintf("exchange/user1/email/inbox/mail%v", i), ItemInfo: details.ItemInfo{ Exchange: &details.ExchangeInfo{ Sender: "John Doe", diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 69de2e45e..2832c054e 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -27,7 +27,7 @@ import ( const ( testTenant = "a-tenant" testUser = "user1" - testEmailDir = "mail" + testEmailDir = "email" testInboxDir = "inbox" testArchiveDir = "archive" testFileName = "file1" diff --git a/src/internal/path/resource_path.go b/src/internal/path/resource_path.go index 4f768f080..3539414fb 100644 --- a/src/internal/path/resource_path.go +++ b/src/internal/path/resource_path.go @@ -33,7 +33,7 @@ const ( EventsCategory // events ) -func toCategoryType(category string) CategoryType { +func ToCategoryType(category string) CategoryType { switch category { case EmailCategory.String(): return EmailCategory @@ -59,7 +59,7 @@ func validateServiceAndCategory(s, c string) (ServiceType, CategoryType, error) // Validity of service checked on first-level lookup to serviceCategories. service := toServiceType(s) - category := toCategoryType(c) + category := ToCategoryType(c) if category == UnknownCategory { return UnknownService, UnknownCategory, errors.Errorf("unknown category string %q", c) } diff --git a/src/pkg/selectors/exchange_test.go b/src/pkg/selectors/exchange_test.go index bd70f8387..6624894b9 100644 --- a/src/pkg/selectors/exchange_test.go +++ b/src/pkg/selectors/exchange_test.go @@ -777,7 +777,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() { ) var ( - path = []string{"tid", usr, "mail", fld, mail} + path = []string{"tid", usr, "email", fld, mail} es = NewExchangeRestore() ) @@ -843,7 +843,7 @@ func (suite *ExchangeSelectorSuite) TestIdPath() { }, { ExchangeMail, - []string{"tid", "uid", "mail", "mFld", "mid"}, + []string{"tid", "uid", "email", "mFld", "mid"}, map[exchangeCategory]string{ ExchangeUser: "uid", ExchangeMailFolder: "mFld", @@ -883,7 +883,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() { const ( contact = "tid/uid/contacts/cfld/cid" event = "tid/uid/events/ecld/eid" - mail = "tid/uid/mail/mfld/mid" + mail = "tid/uid/email/mfld/mid" ) arr := func(s ...string) []string { @@ -1090,7 +1090,7 @@ func (suite *ExchangeSelectorSuite) TestPasses() { mail = setScopesToDefault(es.Mails(Any(), Any(), []string{mid})) otherMail = setScopesToDefault(es.Mails(Any(), Any(), []string{"smarf"})) noMail = setScopesToDefault(es.Mails(Any(), Any(), None())) - path = []string{"tid", "user", "mail", "folder", mid} + path = []string{"tid", "user", "email", "folder", mid} ) table := []struct { @@ -1175,7 +1175,7 @@ func (suite *ExchangeSelectorSuite) TestIsAny() { es = NewExchangeRestore() anyUser = setScopesToDefault(es.Users(Any())) noUser = setScopesToDefault(es.Users(None())) - specificMail = setScopesToDefault(es.Mails(Any(), Any(), []string{"mail"})) + specificMail = setScopesToDefault(es.Mails(Any(), Any(), []string{"email"})) anyMail = setScopesToDefault(es.Mails(Any(), Any(), Any())) ) diff --git a/src/pkg/selectors/scopes.go b/src/pkg/selectors/scopes.go index 33804dea1..68f42aac8 100644 --- a/src/pkg/selectors/scopes.go +++ b/src/pkg/selectors/scopes.go @@ -3,6 +3,7 @@ package selectors import ( "strings" + "github.com/alcionai/corso/internal/path" "github.com/alcionai/corso/pkg/backup/details" "github.com/alcionai/corso/pkg/filters" ) @@ -240,16 +241,16 @@ func reduce[T scopeT, C categoryT]( // for each entry, compare that entry against the scopes of the same data type for _, ent := range deets.Entries { // todo: use Path pkg for this - path := strings.Split(ent.RepoRef, "/") + repoPath := strings.Split(ent.RepoRef, "/") - dc, ok := dataCategories[pathTypeIn(path)] + dc, ok := dataCategories[pathTypeIn(repoPath)] if !ok { continue } passed := passes( dc, - dc.pathValues(path), + dc.pathValues(repoPath), ent, excls[dc], filts[dc], @@ -283,19 +284,19 @@ const ( // package. It should get handled in paths, since that's where service- and // data-type-specific assertions are owned. // Ideally, we'd use something like path.DataType() instead of this func. -func pathTypeIn(path []string) pathType { +func pathTypeIn(p []string) pathType { // not all paths will be len=3. Most should be longer. // This just protects us from panicing below. - if len(path) < 3 { + if len(p) < 3 { return unknownPathType } - switch path[2] { - case "mail": + switch p[2] { + case path.EmailCategory.String(): return exchangeMailPath - case "contacts": + case path.ContactsCategory.String(): return exchangeContactPath - case "events": + case path.EventsCategory.String(): return exchangeEventPath } diff --git a/src/pkg/selectors/scopes_test.go b/src/pkg/selectors/scopes_test.go index 96a7ade88..c268be621 100644 --- a/src/pkg/selectors/scopes_test.go +++ b/src/pkg/selectors/scopes_test.go @@ -243,7 +243,7 @@ func (suite *SelectorScopesSuite) TestReduce() { func (suite *SelectorScopesSuite) TestPathTypeIn() { t := suite.T() assert.Equal(t, unknownPathType, pathTypeIn([]string{}), "empty") - assert.Equal(t, exchangeMailPath, pathTypeIn([]string{"", "", "mail"}), "mail") + assert.Equal(t, exchangeMailPath, pathTypeIn([]string{"", "", "email"}), "email") assert.Equal(t, exchangeContactPath, pathTypeIn([]string{"", "", "contacts"}), "contact") assert.Equal(t, exchangeEventPath, pathTypeIn([]string{"", "", "events"}), "event") assert.Equal(t, unknownPathType, pathTypeIn([]string{"", "", "fnords"}), "bogus")