diff --git a/src/cmd/factory/impl/common.go b/src/cmd/factory/impl/common.go index d1855b108..f530e1d92 100644 --- a/src/cmd/factory/impl/common.go +++ b/src/cmd/factory/impl/common.go @@ -26,6 +26,7 @@ import ( "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/control" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/credentials" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/path" @@ -397,7 +398,7 @@ func generateAndRestoreDriveItems( Service: service, Tenant: tenantID, ResourceOwners: []string{resourceOwner}, - RestoreCfg: tester.DefaultTestRestoreConfig(""), + RestoreCfg: testdata.DefaultRestoreConfig(""), } _, _, collections, _, err := m365Stub.GetCollectionsAndExpected( diff --git a/src/internal/m365/controller_test.go b/src/internal/m365/controller_test.go index 2d63e4261..6d181eb66 100644 --- a/src/internal/m365/controller_test.go +++ b/src/internal/m365/controller_test.go @@ -22,6 +22,7 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/pkg/control" + "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" @@ -296,7 +297,7 @@ func (suite *ControllerIntegrationSuite) TestRestoreFailsBadService() { defer flush() var ( - restoreCfg = tester.DefaultTestRestoreConfig("") + restoreCfg = testdata.DefaultRestoreConfig("") sel = selectors.Selector{ Service: selectors.ServiceUnknown, } @@ -323,7 +324,7 @@ func (suite *ControllerIntegrationSuite) TestRestoreFailsBadService() { } func (suite *ControllerIntegrationSuite) TestEmptyCollections() { - restoreCfg := tester.DefaultTestRestoreConfig("") + restoreCfg := testdata.DefaultRestoreConfig("") table := []struct { name string col []data.RestoreCollection @@ -539,7 +540,7 @@ func runRestoreBackupTest( Service: test.service, Tenant: tenant, ResourceOwners: resourceOwners, - RestoreCfg: tester.DefaultTestRestoreConfig(""), + RestoreCfg: testdata.DefaultRestoreConfig(""), } totalItems, totalKopiaItems, collections, expectedData, err := stub.GetCollectionsAndExpected( @@ -584,7 +585,7 @@ func runRestoreTestWithVersion( Service: test.service, Tenant: tenant, ResourceOwners: resourceOwners, - RestoreCfg: tester.DefaultTestRestoreConfig(""), + RestoreCfg: testdata.DefaultRestoreConfig(""), } totalItems, _, collections, _, err := stub.GetCollectionsAndExpected( @@ -621,7 +622,7 @@ func runRestoreBackupTestVersions( Service: test.service, Tenant: tenant, ResourceOwners: resourceOwners, - RestoreCfg: tester.DefaultTestRestoreConfig(""), + RestoreCfg: testdata.DefaultRestoreConfig(""), } totalItems, _, collections, _, err := stub.GetCollectionsAndExpected( @@ -997,7 +998,7 @@ func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() { for i, collection := range test.collections { // Get a restoreCfg per collection so they're independent. - restoreCfg := tester.DefaultTestRestoreConfig("") + restoreCfg := testdata.DefaultRestoreConfig("") expectedDests = append(expectedDests, destAndCats{ resourceOwner: suite.user, dest: restoreCfg.Location, diff --git a/src/internal/m365/exchange/contacts_restore_test.go b/src/internal/m365/exchange/contacts_restore_test.go index 2eff0d6a6..de53f59e2 100644 --- a/src/internal/m365/exchange/contacts_restore_test.go +++ b/src/internal/m365/exchange/contacts_restore_test.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -51,7 +52,7 @@ func (suite *ContactsRestoreIntgSuite) TestCreateContainerDestination() { path.EmailCategory, suite.creds.AzureTenantID, suite.userID, - tester.DefaultTestRestoreConfig("").Location, + testdata.DefaultRestoreConfig("").Location, []string{"Hufflepuff"}, []string{"Ravenclaw"}) } diff --git a/src/internal/m365/exchange/events_restore_test.go b/src/internal/m365/exchange/events_restore_test.go index dcce8c5f3..156d191d1 100644 --- a/src/internal/m365/exchange/events_restore_test.go +++ b/src/internal/m365/exchange/events_restore_test.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -51,7 +52,7 @@ func (suite *EventsRestoreIntgSuite) TestCreateContainerDestination() { path.EmailCategory, suite.creds.AzureTenantID, suite.userID, - tester.DefaultTestRestoreConfig("").Location, + testdata.DefaultRestoreConfig("").Location, []string{"Durmstrang"}, []string{"Beauxbatons"}) } diff --git a/src/internal/m365/exchange/mail_restore_test.go b/src/internal/m365/exchange/mail_restore_test.go index 74ac9e87a..9d71de800 100644 --- a/src/internal/m365/exchange/mail_restore_test.go +++ b/src/internal/m365/exchange/mail_restore_test.go @@ -9,6 +9,7 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -51,7 +52,7 @@ func (suite *MailRestoreIntgSuite) TestCreateContainerDestination() { path.EmailCategory, suite.creds.AzureTenantID, suite.userID, - tester.DefaultTestRestoreConfig("").Location, + testdata.DefaultRestoreConfig("").Location, []string{"Griffindor", "Croix"}, []string{"Griffindor", "Felicius"}) } diff --git a/src/internal/m365/exchange/restore_test.go b/src/internal/m365/exchange/restore_test.go index 5b4bbb825..a4e985620 100644 --- a/src/internal/m365/exchange/restore_test.go +++ b/src/internal/m365/exchange/restore_test.go @@ -13,6 +13,7 @@ import ( exchMock "github.com/alcionai/corso/src/internal/m365/exchange/mock" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" + "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/services/m365/api" @@ -54,7 +55,7 @@ func (suite *RestoreIntgSuite) TestRestoreContact() { var ( userID = tester.M365UserID(t) - folderName = tester.DefaultTestRestoreConfig("contact").Location + folderName = testdata.DefaultRestoreConfig("contact").Location handler = newContactRestoreHandler(suite.ac) ) @@ -88,7 +89,7 @@ func (suite *RestoreIntgSuite) TestRestoreEvent() { var ( userID = tester.M365UserID(t) - subject = tester.DefaultTestRestoreConfig("event").Location + subject = testdata.DefaultRestoreConfig("event").Location handler = newEventRestoreHandler(suite.ac) ) @@ -154,7 +155,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageBytes("Restore Exchange Object"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailobj").Location + folderName := testdata.DefaultRestoreConfig("mailobj").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -167,7 +168,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithDirectAttachment("Restore 1 Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailwattch").Location + folderName := testdata.DefaultRestoreConfig("mailwattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -180,7 +181,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithItemAttachmentEvent("Event Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("eventwattch").Location + folderName := testdata.DefaultRestoreConfig("eventwattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -193,7 +194,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithItemAttachmentMail("Mail Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailitemattch").Location + folderName := testdata.DefaultRestoreConfig("mailitemattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -209,7 +210,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { ), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailbasicattch").Location + folderName := testdata.DefaultRestoreConfig("mailbasicattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -225,7 +226,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { ), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailnestattch").Location + folderName := testdata.DefaultRestoreConfig("mailnestattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -241,7 +242,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { ), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailcontactattch").Location + folderName := testdata.DefaultRestoreConfig("mailcontactattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -254,7 +255,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithNestedItemAttachmentEvent("Nested Item Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("nestedattch").Location + folderName := testdata.DefaultRestoreConfig("nestedattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -267,7 +268,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithLargeAttachment("Restore Large Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("maillargeattch").Location + folderName := testdata.DefaultRestoreConfig("maillargeattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -280,7 +281,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithTwoAttachments("Restore 2 Attachments"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailtwoattch").Location + folderName := testdata.DefaultRestoreConfig("mailtwoattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -293,7 +294,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.MessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"), category: path.EmailCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("mailrefattch").Location + folderName := testdata.DefaultRestoreConfig("mailrefattch").Location folder, err := handlers[path.EmailCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -306,7 +307,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.ContactBytes("Test_Omega"), category: path.ContactsCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("contact").Location + folderName := testdata.DefaultRestoreConfig("contact").Location folder, err := handlers[path.ContactsCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -319,7 +320,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.EventBytes("Restored Event Object"), category: path.EventsCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("event").Location + folderName := testdata.DefaultRestoreConfig("event").Location calendar, err := handlers[path.EventsCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) @@ -332,7 +333,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() { bytes: exchMock.EventWithAttachment("Restored Event Attachment"), category: path.EventsCategory, destination: func(t *testing.T, ctx context.Context) string { - folderName := tester.DefaultTestRestoreConfig("eventobj").Location + folderName := testdata.DefaultRestoreConfig("eventobj").Location calendar, err := handlers[path.EventsCategory]. CreateContainer(ctx, userID, folderName, "") require.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/m365/onedrive/item_test.go b/src/internal/m365/onedrive/item_test.go index fd3497fc4..5fd36d345 100644 --- a/src/internal/m365/onedrive/item_test.go +++ b/src/internal/m365/onedrive/item_test.go @@ -15,6 +15,7 @@ import ( "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -155,7 +156,7 @@ func (suite *ItemIntegrationSuite) TestItemWriter() { root, err := suite.service.ac.Drives().GetRootFolder(ctx, test.driveID) require.NoError(t, err, clues.ToCore(err)) - newFolderName := tester.DefaultTestRestoreConfig("folder").Location + newFolderName := testdata.DefaultRestoreConfig("folder").Location t.Logf("creating folder %s", newFolderName) newFolder, err := rh.PostItemInContainer( diff --git a/src/internal/m365/onedrive/url_cache_test.go b/src/internal/m365/onedrive/url_cache_test.go index 6a6c696b8..a7bafb68e 100644 --- a/src/internal/m365/onedrive/url_cache_test.go +++ b/src/internal/m365/onedrive/url_cache_test.go @@ -17,6 +17,7 @@ import ( "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -65,7 +66,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { t = suite.T() ac = suite.ac.Drives() driveID = suite.driveID - newFolderName = tester.DefaultTestRestoreConfig("folder").Location + newFolderName = testdata.DefaultRestoreConfig("folder").Location driveItemPager = suite.ac.Drives().NewItemPager(driveID, "", api.DriveItemSelectDefault()) ) diff --git a/src/internal/m365/sharepoint/api/pages_test.go b/src/internal/m365/sharepoint/api/pages_test.go index 0f2fa0471..58406557e 100644 --- a/src/internal/m365/sharepoint/api/pages_test.go +++ b/src/internal/m365/sharepoint/api/pages_test.go @@ -16,6 +16,7 @@ import ( spMock "github.com/alcionai/corso/src/internal/m365/sharepoint/mock" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/fault" ) @@ -92,7 +93,7 @@ func (suite *SharePointPageSuite) TestRestoreSinglePage() { ctx, flush := tester.NewContext(t) defer flush() - destName := tester.DefaultTestRestoreConfig("").Location + destName := testdata.DefaultRestoreConfig("").Location testName := "MockPage" // Create Test Page diff --git a/src/internal/m365/sharepoint/collection_test.go b/src/internal/m365/sharepoint/collection_test.go index 5177ecf06..76d26d3ed 100644 --- a/src/internal/m365/sharepoint/collection_test.go +++ b/src/internal/m365/sharepoint/collection_test.go @@ -19,6 +19,7 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" + "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/services/m365/api" @@ -208,7 +209,7 @@ func (suite *SharePointCollectionSuite) TestListCollection_Restore() { info: listToSPInfo(listing, int64(len(byteArray))), } - destName := tester.DefaultTestRestoreConfig("").Location + destName := testdata.DefaultRestoreConfig("").Location deets, err := restoreListItem(ctx, service, listData, suite.siteID, destName) assert.NoError(t, err, clues.ToCore(err)) diff --git a/src/internal/operations/restore.go b/src/internal/operations/restore.go index ef7e7ea38..c301daf5b 100644 --- a/src/internal/operations/restore.go +++ b/src/internal/operations/restore.go @@ -68,7 +68,7 @@ func NewRestoreOperation( operation: newOperation(opts, bus, kw, sw), acct: acct, BackupID: backupID, - RestoreCfg: restoreCfg, + RestoreCfg: control.EnsureRestoreConfigDefaults(ctx, restoreCfg), Selectors: sel, Version: "v0", rc: rc, diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 5eb1d4fda..7faa5051d 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -28,6 +28,7 @@ import ( "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control/repository" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/store" @@ -51,7 +52,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { sw = &store.Wrapper{} ctrl = &mock.Controller{} now = time.Now() - restoreCfg = tester.DefaultTestRestoreConfig("") + restoreCfg = testdata.DefaultRestoreConfig("") ) table := []struct { @@ -219,7 +220,7 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() { kw = &kopia.Wrapper{} sw = &store.Wrapper{} ctrl = &mock.Controller{} - restoreCfg = tester.DefaultTestRestoreConfig("") + restoreCfg = testdata.DefaultRestoreConfig("") opts = control.Defaults() ) @@ -378,7 +379,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() { { name: "Exchange_Restore", owner: tester.M365UserID(suite.T()), - restoreCfg: tester.DefaultTestRestoreConfig(""), + restoreCfg: testdata.DefaultRestoreConfig(""), getSelector: func(t *testing.T, owners []string) selectors.Selector { rsel := selectors.NewExchangeRestore(owners) rsel.Include(rsel.AllData()) @@ -454,7 +455,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoBackup() { defer flush() var ( - restoreCfg = tester.DefaultTestRestoreConfig("") + restoreCfg = testdata.DefaultRestoreConfig("") mb = evmock.NewBus() ) diff --git a/src/pkg/control/options.go b/src/pkg/control/options.go index 4f592787e..d82907397 100644 --- a/src/pkg/control/options.go +++ b/src/pkg/control/options.go @@ -1,8 +1,14 @@ package control import ( + "context" + "strings" + + "golang.org/x/exp/slices" + "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/pkg/control/repository" + "github.com/alcionai/corso/src/pkg/logger" ) // Options holds the optional configurations for a process @@ -64,6 +70,8 @@ const ( Replace CollisionPolicy = "replace" ) +const RootLocation = "/" + // RestoreConfig contains type RestoreConfig struct { // Defines the per-item collision handling policy. @@ -94,6 +102,29 @@ func DefaultRestoreConfig(timeFormat dttm.TimeFormat) RestoreConfig { } } +// EnsureRestoreConfigDefaults sets all non-supported values in the config +// struct to the default value. +func EnsureRestoreConfigDefaults( + ctx context.Context, + rc RestoreConfig, +) RestoreConfig { + if !slices.Contains([]CollisionPolicy{Skip, Copy, Replace}, rc.OnCollision) { + logger.Ctx(ctx). + With( + "bad_collision_policy", rc.OnCollision, + "default_collision_policy", Skip). + Info("setting collision policy to default") + + rc.OnCollision = Skip + } + + if strings.TrimSpace(rc.Location) == RootLocation { + rc.Location = "" + } + + return rc +} + // --------------------------------------------------------------------------- // Feature Flags and Toggles // --------------------------------------------------------------------------- diff --git a/src/pkg/control/options_test.go b/src/pkg/control/options_test.go new file mode 100644 index 000000000..eac04ddfa --- /dev/null +++ b/src/pkg/control/options_test.go @@ -0,0 +1,83 @@ +package control + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/tester" +) + +type OptionsUnitSuite struct { + tester.Suite +} + +func TestOptionsUnitSuite(t *testing.T) { + suite.Run(t, &OptionsUnitSuite{Suite: tester.NewUnitSuite(t)}) +} + +func (suite *OptionsUnitSuite) TestEnsureRestoreConfigDefaults() { + table := []struct { + name string + input RestoreConfig + expect RestoreConfig + }{ + { + name: "populated", + input: RestoreConfig{ + OnCollision: Copy, + ProtectedResource: "batman", + Location: "badman", + Drive: "hatman", + }, + expect: RestoreConfig{ + OnCollision: Copy, + ProtectedResource: "batman", + Location: "badman", + Drive: "hatman", + }, + }, + { + name: "unpopulated", + input: RestoreConfig{ + OnCollision: Unknown, + ProtectedResource: "", + Location: "", + Drive: "", + }, + expect: RestoreConfig{ + OnCollision: Skip, + ProtectedResource: "", + Location: "", + Drive: "", + }, + }, + { + name: "populated, but modified", + input: RestoreConfig{ + OnCollision: CollisionPolicy("batman"), + ProtectedResource: "", + Location: "/", + Drive: "", + }, + expect: RestoreConfig{ + OnCollision: Skip, + ProtectedResource: "", + Location: "", + Drive: "", + }, + }, + } + for _, test := range table { + suite.Run(test.name, func() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + result := EnsureRestoreConfigDefaults(ctx, test.input) + assert.Equal(t, test.expect, result) + }) + } +} diff --git a/src/internal/tester/restore_destination.go b/src/pkg/control/testdata/testdata.go similarity index 85% rename from src/internal/tester/restore_destination.go rename to src/pkg/control/testdata/testdata.go index 5b1c667c3..5c4f5df20 100644 --- a/src/internal/tester/restore_destination.go +++ b/src/pkg/control/testdata/testdata.go @@ -1,4 +1,4 @@ -package tester +package testdata import ( "strings" @@ -9,7 +9,7 @@ import ( const RestoreFolderPrefix = "Corso_Test" -func DefaultTestRestoreConfig(namespace string) control.RestoreConfig { +func DefaultRestoreConfig(namespace string) control.RestoreConfig { var ( restoreCfg = control.DefaultRestoreConfig(dttm.SafeForTesting) sft = dttm.FormatNow(dttm.SafeForTesting) diff --git a/src/pkg/repository/loadtest/repository_load_test.go b/src/pkg/repository/loadtest/repository_load_test.go index 9f586f648..86711a84f 100644 --- a/src/pkg/repository/loadtest/repository_load_test.go +++ b/src/pkg/repository/loadtest/repository_load_test.go @@ -20,6 +20,7 @@ import ( "github.com/alcionai/corso/src/pkg/backup" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/control" + ctrlTD "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/repository" @@ -151,7 +152,7 @@ func runRestoreLoadTest( t.Skip("restore load test is toggled off") } - restoreCfg := tester.DefaultTestRestoreConfig("") + restoreCfg := ctrlTD.DefaultRestoreConfig("") rst, err := r.NewRestore(ctx, backupID, restSel, restoreCfg) require.NoError(t, err, clues.ToCore(err)) diff --git a/src/pkg/repository/repository_test.go b/src/pkg/repository/repository_test.go index f3a06cc9e..84b876d9d 100644 --- a/src/pkg/repository/repository_test.go +++ b/src/pkg/repository/repository_test.go @@ -13,7 +13,8 @@ import ( "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" - rep "github.com/alcionai/corso/src/pkg/control/repository" + ctrlRepo "github.com/alcionai/corso/src/pkg/control/repository" + "github.com/alcionai/corso/src/pkg/control/testdata" "github.com/alcionai/corso/src/pkg/repository" "github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/storage" @@ -242,7 +243,7 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() { defer flush() acct := tester.NewM365Account(t) - restoreCfg := tester.DefaultTestRestoreConfig("") + restoreCfg := testdata.DefaultRestoreConfig("") // need to initialize the repository before we can test connecting to it. st := tester.NewPrefixedS3Storage(t) @@ -269,7 +270,7 @@ func (suite *RepositoryIntegrationSuite) TestNewMaintenance() { r, err := repository.Initialize(ctx, acct, st, control.Defaults()) require.NoError(t, err, clues.ToCore(err)) - mo, err := r.NewMaintenance(ctx, rep.Maintenance{}) + mo, err := r.NewMaintenance(ctx, ctrlRepo.Maintenance{}) require.NoError(t, err, clues.ToCore(err)) require.NotNil(t, mo) }