diff --git a/src/internal/operations/test/exchange_test.go b/src/internal/operations/test/exchange_test.go index b0a9ac2ec..174afea9d 100644 --- a/src/internal/operations/test/exchange_test.go +++ b/src/internal/operations/test/exchange_test.go @@ -904,115 +904,14 @@ func (suite *ExchangeBackupNightlyIntgSuite) SetupSuite() { suite.its = newIntegrationTesterSetup(suite.T()) } -func (suite *ExchangeBackupNightlyIntgSuite) TestBackup_Run_exchangeBasic_groups9VersionBump() { - t := suite.T() - - ctx, flush := tester.NewContext(t) - defer flush() - - var ( - mb = evmock.NewBus() - counter = count.New() - sel = selectors.NewExchangeBackup([]string{suite.its.user.ID}) - opts = control.DefaultOptions() - ws = deeTD.DriveIDFromRepoRef - ) - +func (suite *ExchangeBackupNightlyIntgSuite) TestBackup_Run_exchangeVersion9MergeBase() { + sel := selectors.NewExchangeBackup([]string{suite.its.user.ID}) sel.Include( sel.ContactFolders([]string{api.DefaultContacts}, selectors.PrefixMatch()), // sel.EventCalendars([]string{api.DefaultCalendar}, selectors.PrefixMatch()), sel.MailFolders([]string{api.MailInbox}, selectors.PrefixMatch())) - bo, bod := prepNewTestBackupOp( - t, - ctx, - mb, - sel.Selector, - opts, - version.All8MigrateUserPNToID, - counter) - defer bod.close(t, ctx) - - runAndCheckBackup(t, ctx, &bo, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - &bo, - bod.sel, - bod.sel.ID(), - path.EmailCategory) - - _, expectDeets := deeTD.GetDeetsInBackup( - t, - ctx, - bo.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.ExchangeService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - bo.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - mb = evmock.NewBus() - counter = count.New() - notForcedFull := newTestBackupOp( - t, - ctx, - bod, - mb, - opts, - counter) - notForcedFull.BackupVersion = version.Groups9Update - - runAndCheckBackup(t, ctx, ¬ForcedFull, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - ¬ForcedFull, - bod.sel, - bod.sel.ID(), - path.EmailCategory) - - _, expectDeets = deeTD.GetDeetsInBackup( - t, - ctx, - notForcedFull.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.ExchangeService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - notForcedFull.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - // The number of items backed up in the second backup should be less than the - // number of items in the original backup. - assert.Greater( - t, - bo.Results.Counts[string(count.PersistedNonCachedFiles)], - notForcedFull.Results.Counts[string(count.PersistedNonCachedFiles)], - "items written") + runMergeBaseGroupsUpdate(suite, sel.Selector, true) } type ExchangeRestoreNightlyIntgSuite struct { diff --git a/src/internal/operations/test/group_test.go b/src/internal/operations/test/group_test.go index 1d9afc924..201f78b14 100644 --- a/src/internal/operations/test/group_test.go +++ b/src/internal/operations/test/group_test.go @@ -4,7 +4,6 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" evmock "github.com/alcionai/corso/src/internal/events/mock" @@ -215,114 +214,13 @@ func (suite *GroupsBackupNightlyIntgSuite) SetupSuite() { suite.its = newIntegrationTesterSetup(suite.T()) } -func (suite *GroupsBackupNightlyIntgSuite) TestBackup_Run_groupsBasic_groups9VersionBump() { - t := suite.T() - - ctx, flush := tester.NewContext(t) - defer flush() - - var ( - mb = evmock.NewBus() - counter = count.New() - sel = selectors.NewGroupsBackup([]string{suite.its.group.ID}) - opts = control.DefaultOptions() - whatSet = deeTD.CategoryFromRepoRef - ) - +func (suite *GroupsBackupNightlyIntgSuite) TestBackup_Run_groupsVersion9MergeBase() { + sel := selectors.NewGroupsBackup([]string{suite.its.group.ID}) sel.Include( selTD.GroupsBackupLibraryFolderScope(sel), selTD.GroupsBackupChannelScope(sel)) - bo, bod := prepNewTestBackupOp( - t, - ctx, - mb, - sel.Selector, - opts, - version.All8MigrateUserPNToID, - counter) - defer bod.close(t, ctx) - - runAndCheckBackup(t, ctx, &bo, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - &bo, - bod.sel, - bod.sel.ID(), - path.ChannelMessagesCategory) - - _, expectDeets := deeTD.GetDeetsInBackup( - t, - ctx, - bo.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.GroupsService, - whatSet, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - bo.Results.BackupID, - whatSet, - bod.kms, - bod.sss, - expectDeets, - false) - - mb = evmock.NewBus() - counter = count.New() - forcedFull := newTestBackupOp( - t, - ctx, - bod, - mb, - opts, - counter) - forcedFull.BackupVersion = version.Groups9Update - - runAndCheckBackup(t, ctx, &forcedFull, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - &forcedFull, - bod.sel, - bod.sel.ID(), - path.ChannelMessagesCategory) - - _, expectDeets = deeTD.GetDeetsInBackup( - t, - ctx, - forcedFull.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.GroupsService, - whatSet, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - forcedFull.Results.BackupID, - whatSet, - bod.kms, - bod.sss, - expectDeets, - false) - - // The number of items backed up in the forced full backup should be roughly - // the same as the number of items in the original backup. - assert.Equal( - t, - bo.Results.Counts[string(count.PersistedNonCachedFiles)], - forcedFull.Results.Counts[string(count.PersistedNonCachedFiles)], - "items written") + runMergeBaseGroupsUpdate(suite, sel.Selector, false) } func (suite *GroupsBackupNightlyIntgSuite) TestBackup_Run_groupsVersion9AssistBases() { diff --git a/src/internal/operations/test/helper_test.go b/src/internal/operations/test/helper_test.go index beb25dfb9..22dc48ea8 100644 --- a/src/internal/operations/test/helper_test.go +++ b/src/internal/operations/test/helper_test.go @@ -28,9 +28,11 @@ import ( "github.com/alcionai/corso/src/internal/streamstore" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester/tconfig" + "github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/backup" "github.com/alcionai/corso/src/pkg/backup/details" + deeTD "github.com/alcionai/corso/src/pkg/backup/details/testdata" "github.com/alcionai/corso/src/pkg/backup/identity" "github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control/repository" @@ -374,6 +376,147 @@ func checkMetadataFilesExist( } } +func runMergeBaseGroupsUpdate( + suite tester.Suite, + sel selectors.Selector, + expectCached bool, +) { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + var ( + mb = evmock.NewBus() + opts = control.DefaultOptions() + whatSet = deeTD.CategoryFromRepoRef + ) + + // Need outside the inner test case so bod lasts for the entire test. + bo, bod := prepNewTestBackupOp( + t, + ctx, + mb, + sel, + opts, + version.All8MigrateUserPNToID, + count.New()) + defer bod.close(t, ctx) + + suite.Run("makeMergeBackup", func() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + runAndCheckBackup(t, ctx, &bo, mb, false) + + reasons, err := bod.sel.Reasons(bod.acct.ID(), false) + require.NoError(t, err, clues.ToCore(err)) + + for _, reason := range reasons { + checkBackupIsInManifests( + t, + ctx, + bod.kw, + bod.sw, + &bo, + bod.sel, + bod.sel.ID(), + reason.Category()) + } + + _, expectDeets := deeTD.GetDeetsInBackup( + t, + ctx, + bo.Results.BackupID, + bod.acct.ID(), + bod.sel.ID(), + bod.sel.PathService(), + whatSet, + bod.kms, + bod.sss) + deeTD.CheckBackupDetails( + t, + ctx, + bo.Results.BackupID, + whatSet, + bod.kms, + bod.sss, + expectDeets, + false) + }) + + suite.Run("makeIncrementalBackup", func() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + var ( + mb = evmock.NewBus() + opts = control.DefaultOptions() + ) + + forcedFull := newTestBackupOp( + t, + ctx, + bod, + mb, + opts, + count.New()) + forcedFull.BackupVersion = version.Groups9Update + + runAndCheckBackup(t, ctx, &forcedFull, mb, false) + + reasons, err := bod.sel.Reasons(bod.acct.ID(), false) + require.NoError(t, err, clues.ToCore(err)) + + for _, reason := range reasons { + checkBackupIsInManifests( + t, + ctx, + bod.kw, + bod.sw, + &forcedFull, + bod.sel, + bod.sel.ID(), + reason.Category()) + } + + _, expectDeets := deeTD.GetDeetsInBackup( + t, + ctx, + forcedFull.Results.BackupID, + bod.acct.ID(), + bod.sel.ID(), + bod.sel.PathService(), + whatSet, + bod.kms, + bod.sss) + deeTD.CheckBackupDetails( + t, + ctx, + forcedFull.Results.BackupID, + whatSet, + bod.kms, + bod.sss, + expectDeets, + false) + + check := assert.Zero + + if expectCached { + check = assert.NotZero + } + + check( + t, + forcedFull.Results.Counts[string(count.PersistedCachedFiles)], + "cached items") + }) +} + // --------------------------------------------------------------------------- // Incremental Item Generators // TODO: this is ripped from factory.go, which is ripped from other tests. diff --git a/src/internal/operations/test/onedrive_test.go b/src/internal/operations/test/onedrive_test.go index 8f3a610c1..e70613ba2 100644 --- a/src/internal/operations/test/onedrive_test.go +++ b/src/internal/operations/test/onedrive_test.go @@ -1189,7 +1189,7 @@ type OneDriveBackupNightlyIntgSuite struct { } func TestOneDriveBackupNightlyIntgSuite(t *testing.T) { - suite.Run(t, &OneDriveBackupIntgSuite{ + suite.Run(t, &OneDriveBackupNightlyIntgSuite{ Suite: tester.NewNightlySuite( t, [][]string{tconfig.M365AcctCredEnvs, storeTD.AWSStorageCredEnvs}), @@ -1200,113 +1200,11 @@ func (suite *OneDriveBackupNightlyIntgSuite) SetupSuite() { suite.its = newIntegrationTesterSetup(suite.T()) } -func (suite *OneDriveBackupNightlyIntgSuite) TestBackup_Run_oneDriveBasic_groups9VersionBump() { - t := suite.T() +func (suite *OneDriveBackupNightlyIntgSuite) TestBackup_Run_oneDriveVersion9MergeBase() { + sel := selectors.NewOneDriveBackup([]string{suite.its.user.ID}) + sel.Include(selTD.OneDriveBackupFolderScope(sel)) - ctx, flush := tester.NewContext(t) - defer flush() - - var ( - mb = evmock.NewBus() - counter = count.New() - userID = tconfig.SecondaryM365UserID(t) - osel = selectors.NewOneDriveBackup([]string{userID}) - ws = deeTD.DriveIDFromRepoRef - opts = control.DefaultOptions() - ) - - osel.Include(selTD.OneDriveBackupFolderScope(osel)) - - bo, bod := prepNewTestBackupOp( - t, - ctx, - mb, - osel.Selector, - opts, - version.All8MigrateUserPNToID, - counter) - defer bod.close(t, ctx) - - runAndCheckBackup(t, ctx, &bo, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - &bo, - bod.sel, - bod.sel.ID(), - path.FilesCategory) - - _, expectDeets := deeTD.GetDeetsInBackup( - t, - ctx, - bo.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.OneDriveService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - bo.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - mb = evmock.NewBus() - counter = count.New() - notForcedFull := newTestBackupOp( - t, - ctx, - bod, - mb, - opts, - counter) - notForcedFull.BackupVersion = version.Groups9Update - - runAndCheckBackup(t, ctx, ¬ForcedFull, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - ¬ForcedFull, - bod.sel, - bod.sel.ID(), - path.FilesCategory) - - _, expectDeets = deeTD.GetDeetsInBackup( - t, - ctx, - notForcedFull.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.OneDriveService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - notForcedFull.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - // The number of items backed up in the second backup should be less than the - // number of items in the original backup. - assert.Greater( - t, - bo.Results.Counts[string(count.PersistedNonCachedFiles)], - notForcedFull.Results.Counts[string(count.PersistedNonCachedFiles)], - "items written") + runMergeBaseGroupsUpdate(suite, sel.Selector, true) } //func (suite *OneDriveBackupNightlyIntgSuite) TestBackup_Run_oneDriveVersion9AssistBases() { diff --git a/src/internal/operations/test/sharepoint_test.go b/src/internal/operations/test/sharepoint_test.go index f791b41c3..57e4af2d3 100644 --- a/src/internal/operations/test/sharepoint_test.go +++ b/src/internal/operations/test/sharepoint_test.go @@ -200,112 +200,11 @@ func (suite *SharePointBackupNightlyIntgSuite) SetupSuite() { suite.its = newIntegrationTesterSetup(suite.T()) } -func (suite *SharePointBackupNightlyIntgSuite) TestBackup_Run_sharePointBasic_groups9VersionBump() { - t := suite.T() - - ctx, flush := tester.NewContext(t) - defer flush() - - var ( - mb = evmock.NewBus() - counter = count.New() - sel = selectors.NewSharePointBackup([]string{suite.its.site.ID}) - opts = control.DefaultOptions() - ws = deeTD.DriveIDFromRepoRef - ) - +func (suite *SharePointBackupNightlyIntgSuite) TestBackup_Run_sharePointVersion9MergeBase() { + sel := selectors.NewSharePointBackup([]string{suite.its.site.ID}) sel.Include(selTD.SharePointBackupFolderScope(sel)) - bo, bod := prepNewTestBackupOp( - t, - ctx, - mb, - sel.Selector, - opts, - version.All8MigrateUserPNToID, - counter) - defer bod.close(t, ctx) - - runAndCheckBackup(t, ctx, &bo, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - &bo, - bod.sel, - bod.sel.ID(), - path.LibrariesCategory) - - _, expectDeets := deeTD.GetDeetsInBackup( - t, - ctx, - bo.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.SharePointService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - bo.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - mb = evmock.NewBus() - counter = count.New() - notForcedFull := newTestBackupOp( - t, - ctx, - bod, - mb, - opts, - counter) - notForcedFull.BackupVersion = version.Groups9Update - - runAndCheckBackup(t, ctx, ¬ForcedFull, mb, false) - checkBackupIsInManifests( - t, - ctx, - bod.kw, - bod.sw, - ¬ForcedFull, - bod.sel, - bod.sel.ID(), - path.LibrariesCategory) - - _, expectDeets = deeTD.GetDeetsInBackup( - t, - ctx, - notForcedFull.Results.BackupID, - bod.acct.ID(), - bod.sel.ID(), - path.SharePointService, - ws, - bod.kms, - bod.sss) - deeTD.CheckBackupDetails( - t, - ctx, - notForcedFull.Results.BackupID, - ws, - bod.kms, - bod.sss, - expectDeets, - false) - - // The number of items backed up in the second backup should be less than the - // number of items in the original backup. - assert.Greater( - t, - bo.Results.Counts[string(count.PersistedNonCachedFiles)], - notForcedFull.Results.Counts[string(count.PersistedNonCachedFiles)], - "items written") + runMergeBaseGroupsUpdate(suite, sel.Selector, true) } func (suite *SharePointBackupNightlyIntgSuite) TestBackup_Run_sharePointVersion9AssistBases() {