Higher resolution on test restore folder names (#1040)

## Description

\~Only affects folders created by tests\~
Create and use helper function that sets the restore destination folders to have microsecond granularity. This is to avoid naming collisions with second granularity (of which I've observed at least once)

Switches all tests for all services/categories to use OneDrive DateTime format+microseconds

Manually verified that a manually created folder with the given timestamp format was removed by the CI purge script

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Issue(s)

* closes #1036

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-10-04 16:52:13 -07:00 committed by GitHub
parent 630d74bee7
commit 3f0951dea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 20 deletions

View File

@ -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 (

View File

@ -99,6 +99,7 @@ func (suite *CommonTimeUnitSuite) TestExtractTime() {
common.SimpleDateTimeFormatOneDrive,
common.StandardTimeFormat,
common.TabularOutputTimeFormat,
common.SimpleDateTimeFormatTests,
}
type presuf struct {

View File

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

View File

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

View File

@ -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(

View File

@ -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(

View File

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

View File

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

View File

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