add default restore config normalizer (#3613)

Adds a func that normalizes the restore config in case inputs don't match accepted or expected values.

Also moves DefaultTestRestoreConfig out of /tester and into /control/testdata to avoid circular dependency issues.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🌻 Feature

#### Issue(s)

* #3562

#### Test Plan

- [x]  Unit test
This commit is contained in:
Keepers 2023-06-15 10:04:42 -06:00 committed by GitHub
parent dd19b484c8
commit 46eedc0ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 168 additions and 41 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/control" "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/credentials"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
@ -397,7 +398,7 @@ func generateAndRestoreDriveItems(
Service: service, Service: service,
Tenant: tenantID, Tenant: tenantID,
ResourceOwners: []string{resourceOwner}, ResourceOwners: []string{resourceOwner},
RestoreCfg: tester.DefaultTestRestoreConfig(""), RestoreCfg: testdata.DefaultRestoreConfig(""),
} }
_, _, collections, _, err := m365Stub.GetCollectionsAndExpected( _, _, collections, _, err := m365Stub.GetCollectionsAndExpected(

View File

@ -22,6 +22,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/internal/version"
"github.com/alcionai/corso/src/pkg/control" "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/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
@ -296,7 +297,7 @@ func (suite *ControllerIntegrationSuite) TestRestoreFailsBadService() {
defer flush() defer flush()
var ( var (
restoreCfg = tester.DefaultTestRestoreConfig("") restoreCfg = testdata.DefaultRestoreConfig("")
sel = selectors.Selector{ sel = selectors.Selector{
Service: selectors.ServiceUnknown, Service: selectors.ServiceUnknown,
} }
@ -323,7 +324,7 @@ func (suite *ControllerIntegrationSuite) TestRestoreFailsBadService() {
} }
func (suite *ControllerIntegrationSuite) TestEmptyCollections() { func (suite *ControllerIntegrationSuite) TestEmptyCollections() {
restoreCfg := tester.DefaultTestRestoreConfig("") restoreCfg := testdata.DefaultRestoreConfig("")
table := []struct { table := []struct {
name string name string
col []data.RestoreCollection col []data.RestoreCollection
@ -539,7 +540,7 @@ func runRestoreBackupTest(
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
RestoreCfg: tester.DefaultTestRestoreConfig(""), RestoreCfg: testdata.DefaultRestoreConfig(""),
} }
totalItems, totalKopiaItems, collections, expectedData, err := stub.GetCollectionsAndExpected( totalItems, totalKopiaItems, collections, expectedData, err := stub.GetCollectionsAndExpected(
@ -584,7 +585,7 @@ func runRestoreTestWithVersion(
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
RestoreCfg: tester.DefaultTestRestoreConfig(""), RestoreCfg: testdata.DefaultRestoreConfig(""),
} }
totalItems, _, collections, _, err := stub.GetCollectionsAndExpected( totalItems, _, collections, _, err := stub.GetCollectionsAndExpected(
@ -621,7 +622,7 @@ func runRestoreBackupTestVersions(
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
RestoreCfg: tester.DefaultTestRestoreConfig(""), RestoreCfg: testdata.DefaultRestoreConfig(""),
} }
totalItems, _, collections, _, err := stub.GetCollectionsAndExpected( totalItems, _, collections, _, err := stub.GetCollectionsAndExpected(
@ -997,7 +998,7 @@ func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() {
for i, collection := range test.collections { for i, collection := range test.collections {
// Get a restoreCfg per collection so they're independent. // Get a restoreCfg per collection so they're independent.
restoreCfg := tester.DefaultTestRestoreConfig("") restoreCfg := testdata.DefaultRestoreConfig("")
expectedDests = append(expectedDests, destAndCats{ expectedDests = append(expectedDests, destAndCats{
resourceOwner: suite.user, resourceOwner: suite.user,
dest: restoreCfg.Location, dest: restoreCfg.Location,

View File

@ -9,6 +9,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "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/path"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -51,7 +52,7 @@ func (suite *ContactsRestoreIntgSuite) TestCreateContainerDestination() {
path.EmailCategory, path.EmailCategory,
suite.creds.AzureTenantID, suite.creds.AzureTenantID,
suite.userID, suite.userID,
tester.DefaultTestRestoreConfig("").Location, testdata.DefaultRestoreConfig("").Location,
[]string{"Hufflepuff"}, []string{"Hufflepuff"},
[]string{"Ravenclaw"}) []string{"Ravenclaw"})
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "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/path"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -51,7 +52,7 @@ func (suite *EventsRestoreIntgSuite) TestCreateContainerDestination() {
path.EmailCategory, path.EmailCategory,
suite.creds.AzureTenantID, suite.creds.AzureTenantID,
suite.userID, suite.userID,
tester.DefaultTestRestoreConfig("").Location, testdata.DefaultRestoreConfig("").Location,
[]string{"Durmstrang"}, []string{"Durmstrang"},
[]string{"Beauxbatons"}) []string{"Beauxbatons"})
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "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/path"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -51,7 +52,7 @@ func (suite *MailRestoreIntgSuite) TestCreateContainerDestination() {
path.EmailCategory, path.EmailCategory,
suite.creds.AzureTenantID, suite.creds.AzureTenantID,
suite.userID, suite.userID,
tester.DefaultTestRestoreConfig("").Location, testdata.DefaultRestoreConfig("").Location,
[]string{"Griffindor", "Croix"}, []string{"Griffindor", "Croix"},
[]string{"Griffindor", "Felicius"}) []string{"Griffindor", "Felicius"})
} }

View File

@ -13,6 +13,7 @@ import (
exchMock "github.com/alcionai/corso/src/internal/m365/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/exchange/mock"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "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/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
@ -54,7 +55,7 @@ func (suite *RestoreIntgSuite) TestRestoreContact() {
var ( var (
userID = tester.M365UserID(t) userID = tester.M365UserID(t)
folderName = tester.DefaultTestRestoreConfig("contact").Location folderName = testdata.DefaultRestoreConfig("contact").Location
handler = newContactRestoreHandler(suite.ac) handler = newContactRestoreHandler(suite.ac)
) )
@ -88,7 +89,7 @@ func (suite *RestoreIntgSuite) TestRestoreEvent() {
var ( var (
userID = tester.M365UserID(t) userID = tester.M365UserID(t)
subject = tester.DefaultTestRestoreConfig("event").Location subject = testdata.DefaultRestoreConfig("event").Location
handler = newEventRestoreHandler(suite.ac) handler = newEventRestoreHandler(suite.ac)
) )
@ -154,7 +155,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageBytes("Restore Exchange Object"), bytes: exchMock.MessageBytes("Restore Exchange Object"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailobj").Location folderName := testdata.DefaultRestoreConfig("mailobj").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -167,7 +168,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithDirectAttachment("Restore 1 Attachment"), bytes: exchMock.MessageWithDirectAttachment("Restore 1 Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailwattch").Location folderName := testdata.DefaultRestoreConfig("mailwattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -180,7 +181,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithItemAttachmentEvent("Event Item Attachment"), bytes: exchMock.MessageWithItemAttachmentEvent("Event Item Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("eventwattch").Location folderName := testdata.DefaultRestoreConfig("eventwattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -193,7 +194,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithItemAttachmentMail("Mail Item Attachment"), bytes: exchMock.MessageWithItemAttachmentMail("Mail Item Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailitemattch").Location folderName := testdata.DefaultRestoreConfig("mailitemattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -209,7 +210,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
), ),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailbasicattch").Location folderName := testdata.DefaultRestoreConfig("mailbasicattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -225,7 +226,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
), ),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailnestattch").Location folderName := testdata.DefaultRestoreConfig("mailnestattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -241,7 +242,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
), ),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailcontactattch").Location folderName := testdata.DefaultRestoreConfig("mailcontactattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -254,7 +255,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithNestedItemAttachmentEvent("Nested Item Attachment"), bytes: exchMock.MessageWithNestedItemAttachmentEvent("Nested Item Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("nestedattch").Location folderName := testdata.DefaultRestoreConfig("nestedattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -267,7 +268,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithLargeAttachment("Restore Large Attachment"), bytes: exchMock.MessageWithLargeAttachment("Restore Large Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("maillargeattch").Location folderName := testdata.DefaultRestoreConfig("maillargeattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -280,7 +281,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithTwoAttachments("Restore 2 Attachments"), bytes: exchMock.MessageWithTwoAttachments("Restore 2 Attachments"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailtwoattch").Location folderName := testdata.DefaultRestoreConfig("mailtwoattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -293,7 +294,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.MessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"), bytes: exchMock.MessageWithOneDriveAttachment("Restore Reference(OneDrive) Attachment"),
category: path.EmailCategory, category: path.EmailCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("mailrefattch").Location folderName := testdata.DefaultRestoreConfig("mailrefattch").Location
folder, err := handlers[path.EmailCategory]. folder, err := handlers[path.EmailCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -306,7 +307,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.ContactBytes("Test_Omega"), bytes: exchMock.ContactBytes("Test_Omega"),
category: path.ContactsCategory, category: path.ContactsCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("contact").Location folderName := testdata.DefaultRestoreConfig("contact").Location
folder, err := handlers[path.ContactsCategory]. folder, err := handlers[path.ContactsCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -319,7 +320,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.EventBytes("Restored Event Object"), bytes: exchMock.EventBytes("Restored Event Object"),
category: path.EventsCategory, category: path.EventsCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("event").Location folderName := testdata.DefaultRestoreConfig("event").Location
calendar, err := handlers[path.EventsCategory]. calendar, err := handlers[path.EventsCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
@ -332,7 +333,7 @@ func (suite *RestoreIntgSuite) TestRestoreExchangeObject() {
bytes: exchMock.EventWithAttachment("Restored Event Attachment"), bytes: exchMock.EventWithAttachment("Restored Event Attachment"),
category: path.EventsCategory, category: path.EventsCategory,
destination: func(t *testing.T, ctx context.Context) string { destination: func(t *testing.T, ctx context.Context) string {
folderName := tester.DefaultTestRestoreConfig("eventobj").Location folderName := testdata.DefaultRestoreConfig("eventobj").Location
calendar, err := handlers[path.EventsCategory]. calendar, err := handlers[path.EventsCategory].
CreateContainer(ctx, userID, folderName, "") CreateContainer(ctx, userID, folderName, "")
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))

View File

@ -15,6 +15,7 @@ import (
"github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/common/dttm"
"github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/tester" "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/fault"
"github.com/alcionai/corso/src/pkg/services/m365/api" "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) root, err := suite.service.ac.Drives().GetRootFolder(ctx, test.driveID)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
newFolderName := tester.DefaultTestRestoreConfig("folder").Location newFolderName := testdata.DefaultRestoreConfig("folder").Location
t.Logf("creating folder %s", newFolderName) t.Logf("creating folder %s", newFolderName)
newFolder, err := rh.PostItemInContainer( newFolder, err := rh.PostItemInContainer(

View File

@ -17,6 +17,7 @@ import (
"github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/tester" "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/fault"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
) )
@ -65,7 +66,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
t = suite.T() t = suite.T()
ac = suite.ac.Drives() ac = suite.ac.Drives()
driveID = suite.driveID driveID = suite.driveID
newFolderName = tester.DefaultTestRestoreConfig("folder").Location newFolderName = testdata.DefaultRestoreConfig("folder").Location
driveItemPager = suite.ac.Drives().NewItemPager(driveID, "", api.DriveItemSelectDefault()) driveItemPager = suite.ac.Drives().NewItemPager(driveID, "", api.DriveItemSelectDefault())
) )

View File

@ -16,6 +16,7 @@ import (
spMock "github.com/alcionai/corso/src/internal/m365/sharepoint/mock" spMock "github.com/alcionai/corso/src/internal/m365/sharepoint/mock"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "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/fault"
) )
@ -92,7 +93,7 @@ func (suite *SharePointPageSuite) TestRestoreSinglePage() {
ctx, flush := tester.NewContext(t) ctx, flush := tester.NewContext(t)
defer flush() defer flush()
destName := tester.DefaultTestRestoreConfig("").Location destName := testdata.DefaultRestoreConfig("").Location
testName := "MockPage" testName := "MockPage"
// Create Test Page // Create Test Page

View File

@ -19,6 +19,7 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/control" "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/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
@ -208,7 +209,7 @@ func (suite *SharePointCollectionSuite) TestListCollection_Restore() {
info: listToSPInfo(listing, int64(len(byteArray))), info: listToSPInfo(listing, int64(len(byteArray))),
} }
destName := tester.DefaultTestRestoreConfig("").Location destName := testdata.DefaultRestoreConfig("").Location
deets, err := restoreListItem(ctx, service, listData, suite.siteID, destName) deets, err := restoreListItem(ctx, service, listData, suite.siteID, destName)
assert.NoError(t, err, clues.ToCore(err)) assert.NoError(t, err, clues.ToCore(err))

View File

@ -68,7 +68,7 @@ func NewRestoreOperation(
operation: newOperation(opts, bus, kw, sw), operation: newOperation(opts, bus, kw, sw),
acct: acct, acct: acct,
BackupID: backupID, BackupID: backupID,
RestoreCfg: restoreCfg, RestoreCfg: control.EnsureRestoreConfigDefaults(ctx, restoreCfg),
Selectors: sel, Selectors: sel,
Version: "v0", Version: "v0",
rc: rc, rc: rc,

View File

@ -28,6 +28,7 @@ import (
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/control/repository" "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/selectors"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
"github.com/alcionai/corso/src/pkg/store" "github.com/alcionai/corso/src/pkg/store"
@ -51,7 +52,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
sw = &store.Wrapper{} sw = &store.Wrapper{}
ctrl = &mock.Controller{} ctrl = &mock.Controller{}
now = time.Now() now = time.Now()
restoreCfg = tester.DefaultTestRestoreConfig("") restoreCfg = testdata.DefaultRestoreConfig("")
) )
table := []struct { table := []struct {
@ -219,7 +220,7 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() {
kw = &kopia.Wrapper{} kw = &kopia.Wrapper{}
sw = &store.Wrapper{} sw = &store.Wrapper{}
ctrl = &mock.Controller{} ctrl = &mock.Controller{}
restoreCfg = tester.DefaultTestRestoreConfig("") restoreCfg = testdata.DefaultRestoreConfig("")
opts = control.Defaults() opts = control.Defaults()
) )
@ -378,7 +379,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
{ {
name: "Exchange_Restore", name: "Exchange_Restore",
owner: tester.M365UserID(suite.T()), owner: tester.M365UserID(suite.T()),
restoreCfg: tester.DefaultTestRestoreConfig(""), restoreCfg: testdata.DefaultRestoreConfig(""),
getSelector: func(t *testing.T, owners []string) selectors.Selector { getSelector: func(t *testing.T, owners []string) selectors.Selector {
rsel := selectors.NewExchangeRestore(owners) rsel := selectors.NewExchangeRestore(owners)
rsel.Include(rsel.AllData()) rsel.Include(rsel.AllData())
@ -454,7 +455,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoBackup() {
defer flush() defer flush()
var ( var (
restoreCfg = tester.DefaultTestRestoreConfig("") restoreCfg = testdata.DefaultRestoreConfig("")
mb = evmock.NewBus() mb = evmock.NewBus()
) )

View File

@ -1,8 +1,14 @@
package control package control
import ( import (
"context"
"strings"
"golang.org/x/exp/slices"
"github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/common/dttm"
"github.com/alcionai/corso/src/pkg/control/repository" "github.com/alcionai/corso/src/pkg/control/repository"
"github.com/alcionai/corso/src/pkg/logger"
) )
// Options holds the optional configurations for a process // Options holds the optional configurations for a process
@ -64,6 +70,8 @@ const (
Replace CollisionPolicy = "replace" Replace CollisionPolicy = "replace"
) )
const RootLocation = "/"
// RestoreConfig contains // RestoreConfig contains
type RestoreConfig struct { type RestoreConfig struct {
// Defines the per-item collision handling policy. // 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 // Feature Flags and Toggles
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -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)
})
}
}

View File

@ -1,4 +1,4 @@
package tester package testdata
import ( import (
"strings" "strings"
@ -9,7 +9,7 @@ import (
const RestoreFolderPrefix = "Corso_Test" const RestoreFolderPrefix = "Corso_Test"
func DefaultTestRestoreConfig(namespace string) control.RestoreConfig { func DefaultRestoreConfig(namespace string) control.RestoreConfig {
var ( var (
restoreCfg = control.DefaultRestoreConfig(dttm.SafeForTesting) restoreCfg = control.DefaultRestoreConfig(dttm.SafeForTesting)
sft = dttm.FormatNow(dttm.SafeForTesting) sft = dttm.FormatNow(dttm.SafeForTesting)

View File

@ -20,6 +20,7 @@ import (
"github.com/alcionai/corso/src/pkg/backup" "github.com/alcionai/corso/src/pkg/backup"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/control" "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/fault"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/repository" "github.com/alcionai/corso/src/pkg/repository"
@ -151,7 +152,7 @@ func runRestoreLoadTest(
t.Skip("restore load test is toggled off") t.Skip("restore load test is toggled off")
} }
restoreCfg := tester.DefaultTestRestoreConfig("") restoreCfg := ctrlTD.DefaultRestoreConfig("")
rst, err := r.NewRestore(ctx, backupID, restSel, restoreCfg) rst, err := r.NewRestore(ctx, backupID, restSel, restoreCfg)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))

View File

@ -13,7 +13,8 @@ import (
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/control" "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/repository"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
"github.com/alcionai/corso/src/pkg/storage" "github.com/alcionai/corso/src/pkg/storage"
@ -242,7 +243,7 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() {
defer flush() defer flush()
acct := tester.NewM365Account(t) acct := tester.NewM365Account(t)
restoreCfg := tester.DefaultTestRestoreConfig("") restoreCfg := testdata.DefaultRestoreConfig("")
// need to initialize the repository before we can test connecting to it. // need to initialize the repository before we can test connecting to it.
st := tester.NewPrefixedS3Storage(t) st := tester.NewPrefixedS3Storage(t)
@ -269,7 +270,7 @@ func (suite *RepositoryIntegrationSuite) TestNewMaintenance() {
r, err := repository.Initialize(ctx, acct, st, control.Defaults()) r, err := repository.Initialize(ctx, acct, st, control.Defaults())
require.NoError(t, err, clues.ToCore(err)) 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.NoError(t, err, clues.ToCore(err))
require.NotNil(t, mo) require.NotNil(t, mo)
} }