diff --git a/src/internal/common/time.go b/src/internal/common/time.go index 25e7e5755..30c74ce53 100644 --- a/src/internal/common/time.go +++ b/src/internal/common/time.go @@ -19,6 +19,8 @@ const ( SimpleDateTimeFormatOneDrive = "02-Jan-2006_15-04-05" StandardTimeFormat = time.RFC3339Nano TabularOutputTimeFormat = "2006-01-02T15:04:05Z" + // Format used for test restore destination folders. Microsecond granularity. + SimpleDateTimeFormatTests = SimpleDateTimeFormatOneDrive + ".000000" ) var ( diff --git a/src/internal/common/time_test.go b/src/internal/common/time_test.go index 1c46ce7fa..8223db084 100644 --- a/src/internal/common/time_test.go +++ b/src/internal/common/time_test.go @@ -99,6 +99,7 @@ func (suite *CommonTimeUnitSuite) TestExtractTime() { common.SimpleDateTimeFormatOneDrive, common.StandardTimeFormat, common.TabularOutputTimeFormat, + common.SimpleDateTimeFormatTests, } type presuf struct { diff --git a/src/internal/connector/exchange/exchange_service_test.go b/src/internal/connector/exchange/exchange_service_test.go index 994078462..a0d1ad26a 100644 --- a/src/internal/connector/exchange/exchange_service_test.go +++ b/src/internal/connector/exchange/exchange_service_test.go @@ -469,7 +469,7 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() { // GraphConnector's Restore Workflow based on OptionIdentifier. func (suite *ExchangeServiceSuite) TestGetRestoreContainer() { ctx := context.Background() - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() tests := []struct { name string option path.CategoryType diff --git a/src/internal/connector/graph_connector_disconnected_test.go b/src/internal/connector/graph_connector_disconnected_test.go index dbfc343d2..6a68143e9 100644 --- a/src/internal/connector/graph_connector_disconnected_test.go +++ b/src/internal/connector/graph_connector_disconnected_test.go @@ -10,11 +10,9 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector/support" "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/credentials" "github.com/alcionai/corso/src/pkg/selectors" ) @@ -188,7 +186,7 @@ func (suite *DisconnectedGraphConnectorSuite) TestRestoreFailsBadService() { sel := selectors.Selector{ Service: selectors.ServiceUnknown, } - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive) + dest := tester.DefaultTestRestoreDestination() deets, err := gc.RestoreDataCollections(ctx, sel, dest, nil) assert.Error(t, err) diff --git a/src/internal/connector/graph_connector_test.go b/src/internal/connector/graph_connector_test.go index 9dace9bff..5bb188b69 100644 --- a/src/internal/connector/graph_connector_test.go +++ b/src/internal/connector/graph_connector_test.go @@ -368,7 +368,7 @@ func (suite *GraphConnectorIntegrationSuite) TestCreateAndDeleteCalendar() { } func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() { - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive) + dest := tester.DefaultTestRestoreDestination() table := []struct { name string col []data.Collection @@ -673,7 +673,7 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() { suite.T().Run(test.name, func(t *testing.T) { ctx := context.Background() // Get a dest per test so they're independent. - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive) + dest := tester.DefaultTestRestoreDestination() totalItems, collections, expectedData := collectionsForInfo( t, @@ -878,10 +878,8 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames allExpectedData := map[string]map[string][]byte{} for i, collection := range test.collections { - // Get a dest per collection. Ensure they're independent with a small - // sleep. - time.Sleep(time.Second * 1) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive) + // Get a dest per collection so they're independent. + dest := tester.DefaultTestRestoreDestination() dests = append(dests, dest) totalItems, collections, expectedData := collectionsForInfo( diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 221a77e15..e0fd73913 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/connector/exchange" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -44,7 +43,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { sw = &store.Wrapper{} acct = account.Account{} now = time.Now() - dest = control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest = tester.DefaultTestRestoreDestination() ) table := []struct { @@ -213,7 +212,7 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() { kw := &kopia.Wrapper{} sw := &store.Wrapper{} acct := tester.NewM365Account(suite.T()) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() table := []struct { name string @@ -252,7 +251,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() { rsel := selectors.NewExchangeRestore() rsel.Include(rsel.Users([]string{tester.M365UserID(t)})) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() mb := evmock.NewBus() ro, err := NewRestoreOperation( @@ -292,7 +291,7 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_ErrorNoResults() { rsel := selectors.NewExchangeRestore() rsel.Include(rsel.Users(selectors.None())) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() mb := evmock.NewBus() ro, err := NewRestoreOperation( diff --git a/src/internal/tester/restore_destination.go b/src/internal/tester/restore_destination.go new file mode 100644 index 000000000..d01cf1af2 --- /dev/null +++ b/src/internal/tester/restore_destination.go @@ -0,0 +1,11 @@ +package tester + +import ( + "github.com/alcionai/corso/src/internal/common" + "github.com/alcionai/corso/src/pkg/control" +) + +func DefaultTestRestoreDestination() control.RestoreDestination { + // Use microsecond granularity to help reduce collisions. + return control.DefaultRestoreDestination(common.SimpleDateTimeFormatTests) +} diff --git a/src/pkg/repository/repository_load_test.go b/src/pkg/repository/repository_load_test.go index f5e051b34..fb36e06f6 100644 --- a/src/pkg/repository/repository_load_test.go +++ b/src/pkg/repository/repository_load_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/operations" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" @@ -250,7 +249,7 @@ func (suite *RepositoryLoadTestExchangeSuite) TestExchange() { rsel, err := bsel.ToExchangeRestore() require.NoError(t, err) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() rst, err := r.NewRestore(ctx, bid, rsel.Selector, dest) require.NoError(t, err) @@ -325,7 +324,7 @@ func (suite *RepositoryLoadTestOneDriveSuite) TestOneDrive() { rsel, err := bsel.ToOneDriveRestore() require.NoError(t, err) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormatOneDrive) + dest := tester.DefaultTestRestoreDestination() rst, err := r.NewRestore(ctx, bid, rsel.Selector, dest) require.NoError(t, err) diff --git a/src/pkg/repository/repository_test.go b/src/pkg/repository/repository_test.go index c10e14249..c0a1a7244 100644 --- a/src/pkg/repository/repository_test.go +++ b/src/pkg/repository/repository_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/control" @@ -177,7 +176,7 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() { ctx := context.Background() acct := tester.NewM365Account(t) - dest := control.DefaultRestoreDestination(common.SimpleDateTimeFormat) + dest := tester.DefaultTestRestoreDestination() // need to initialize the repository before we can test connecting to it. st := tester.NewPrefixedS3Storage(t)