clean up exchange adv restore test (#3870)

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

- [x]  No

#### Type of change

- [x] 🤖 Supportability/Tests
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #3562

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-07-27 13:16:11 -06:00 committed by GitHub
parent a973f69d18
commit 34d6c18d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -889,6 +889,26 @@ func (suite *ExchangeRestoreIntgSuite) SetupSuite() {
suite.its = newIntegrationTesterSetup(suite.T()) suite.its = newIntegrationTesterSetup(suite.T())
} }
type clientItemPager interface {
GetItemsInContainerByCollisionKeyer[string]
GetItemIDsInContainer(
ctx context.Context,
userID, containerID string,
) (map[string]struct{}, error)
GetContainerByName(
ctx context.Context,
userID, parentContainerID, containerName string,
) (graph.Container, error)
GetItemsInContainerByCollisionKey(
ctx context.Context,
userID, containerID string,
) (map[string]string, error)
CreateContainer(
ctx context.Context,
userID, parentContainerID, containerName string,
) (graph.Container, error)
}
func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptions() { func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptions() {
t := suite.T() t := suite.T()
@ -924,22 +944,25 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
restoreCfg = ctrlTD.DefaultRestoreConfig("exchange_adv_restore") restoreCfg = ctrlTD.DefaultRestoreConfig("exchange_adv_restore")
sel = rsel.Selector sel = rsel.Selector
userID = sel.ID() userID = sel.ID()
cIDs = map[path.CategoryType]string{
path.ContactsCategory: "",
path.EmailCategory: "",
path.EventsCategory: "",
}
collKeys = map[path.CategoryType]map[string]string{}
countContactsInRestore int
acCont = suite.its.ac.Contacts()
contactIDs map[string]struct{}
countEmailsInRestore int
acMail = suite.its.ac.Mail()
mailIDs map[string]struct{}
countItemsInRestore int countItemsInRestore int
// countEventsInRestore int
// acEvts = suite.its.ac.Events() itemIDs = map[path.CategoryType]map[string]struct{}{}
// eventIDs = []string{} collisionKeys = map[path.CategoryType]map[string]string{}
containerIDs = map[path.CategoryType]string{}
parentContainerIDs = map[path.CategoryType]string{
path.EmailCategory: api.MsgFolderRoot,
}
parentContainerNames = map[path.CategoryType][]string{
path.EmailCategory: {api.MailInbox},
path.ContactsCategory: {},
path.EventsCategory: {},
}
testCategories = map[path.CategoryType]clientItemPager{
path.ContactsCategory: suite.its.ac.Contacts(),
path.EmailCategory: suite.its.ac.Mail(),
// path.EventsCategory: suite.its.ac.Events(),
}
) )
// initial restore // initial restore
@ -971,61 +994,27 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
// get all files in folder, use these as the base // get all files in folder, use these as the base
// set of files to compare against. // set of files to compare against.
// --- contacts for cat, ac := range testCategories {
suite.Run(cat.String(), func() {
t := suite.T()
contGC, err := acCont.GetContainerByName(ctx, userID, "", restoreCfg.Location) ctx, flush := tester.NewContext(t)
require.NoError(t, err, clues.ToCore(err)) defer flush()
cIDs[path.ContactsCategory] = ptr.Val(contGC.GetId()) containers := append([]string{restoreCfg.Location}, parentContainerNames[cat]...)
collKeys[path.ContactsCategory], err = acCont.GetItemsInContainerByCollisionKey( itemIDs[cat], collisionKeys[cat], containerIDs[cat] = getCollKeysAndItemIDs(
t,
ctx, ctx,
ac,
userID, userID,
cIDs[path.ContactsCategory]) parentContainerIDs[cat],
require.NoError(t, err, clues.ToCore(err)) containers...)
countContactsInRestore = len(collKeys[path.ContactsCategory])
t.Log(countContactsInRestore, "contacts restored")
contactIDs, err = acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory]) countItemsInRestore += len(collisionKeys[cat])
require.NoError(t, err, clues.ToCore(err)) })
}
// --- events
// gc, err = acEvts.GetContainerByName(ctx, userID, "", restoreCfg.Location)
// require.NoError(t, err, clues.ToCore(err))
// restoredContainerID[path.EventsCategory] = ptr.Val(gc.GetId())
// collKeys[path.EventsCategory], err = acEvts.GetItemsInContainerByCollisionKey(
// ctx,
// userID,
// cIDs[path.EventsCategory])
// require.NoError(t, err, clues.ToCore(err))
// countEventsInRestore = len(collKeys[path.EventsCategory])
// t.Log(countContactsInRestore, "events restored")
mailGC, err := acMail.GetContainerByName(ctx, userID, api.MsgFolderRoot, restoreCfg.Location)
require.NoError(t, err, clues.ToCore(err))
mailGC, err = acMail.GetContainerByName(ctx, userID, ptr.Val(mailGC.GetId()), api.MailInbox)
require.NoError(t, err, clues.ToCore(err))
cIDs[path.EmailCategory] = ptr.Val(mailGC.GetId())
// --- mail
collKeys[path.EmailCategory], err = acMail.GetItemsInContainerByCollisionKey(
ctx,
userID,
cIDs[path.EmailCategory])
require.NoError(t, err, clues.ToCore(err))
countEmailsInRestore = len(collKeys[path.EmailCategory])
t.Log(countContactsInRestore, "emails restored")
mailIDs, err = acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory])
require.NoError(t, err, clues.ToCore(err))
countItemsInRestore = countContactsInRestore + countEmailsInRestore // + countEventsInRestore
checkRestoreCounts(t, ctr1, 0, 0, countItemsInRestore) checkRestoreCounts(t, ctr1, 0, 0, countItemsInRestore)
}) })
@ -1062,43 +1051,30 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
checkRestoreCounts(t, ctr2, countItemsInRestore, 0, 0) checkRestoreCounts(t, ctr2, countItemsInRestore, 0, 0)
// --- contacts result := map[string]string{}
// get all files in folder, use these as the base for cat, ac := range testCategories {
// set of files to compare against. suite.Run(cat.String(), func() {
result := filterCollisionKeyResults( t := suite.T()
t,
ctx,
userID,
cIDs[path.ContactsCategory],
GetItemsInContainerByCollisionKeyer[string](acCont),
collKeys[path.ContactsCategory])
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory]) ctx, flush := tester.NewContext(t)
require.NoError(t, err, clues.ToCore(err)) defer flush()
assert.Equal(t, contactIDs, currentContactIDs, "ids are equal")
// --- events
// m = checkCollisionKeyResults(t, ctx, userID, cIDs[path.EventsCategory], acEvts, collKeys[path.EventsCategory])
// maps.Copy(result, m)
// --- mail
m := filterCollisionKeyResults( m := filterCollisionKeyResults(
t, t,
ctx, ctx,
userID, userID,
cIDs[path.EmailCategory], containerIDs[cat],
GetItemsInContainerByCollisionKeyer[string](acMail), GetItemsInContainerByCollisionKeyer[string](ac),
collKeys[path.EmailCategory]) collisionKeys[cat])
maps.Copy(result, m) maps.Copy(result, m)
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory]) currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
assert.Equal(t, mailIDs, currentMailIDs, "ids are equal") assert.Equal(t, itemIDs[cat], currentIDs, "ids are equal")
})
}
assert.Len(t, result, 0, "no new items should get added") assert.Len(t, result, 0, "no new items should get added")
}) })
@ -1136,59 +1112,39 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
} }
} }
assert.Len( assert.Len(t, filtEnts, countItemsInRestore, "every item should have been replaced")
t,
filtEnts,
countItemsInRestore,
"every item should have been replaced")
// --- contacts checkRestoreCounts(t, ctr3, 0, countItemsInRestore, 0)
result := filterCollisionKeyResults( result := map[string]string{}
t,
ctx,
userID,
cIDs[path.ContactsCategory],
GetItemsInContainerByCollisionKeyer[string](acCont),
collKeys[path.ContactsCategory])
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory]) for cat, ac := range testCategories {
require.NoError(t, err, clues.ToCore(err)) suite.Run(cat.String(), func() {
t := suite.T()
assert.Equal(t, len(contactIDs), len(currentContactIDs), "count of ids are equal") ctx, flush := tester.NewContext(t)
for orig := range contactIDs { defer flush()
assert.NotContains(t, currentContactIDs, orig, "original item should not exist after replacement")
}
contactIDs = currentContactIDs
// --- events
// m = checkCollisionKeyResults(t, ctx, userID, cIDs[path.EventsCategory], acEvts, collKeys[path.EventsCategory])
// maps.Copy(result, m)
// --- mail
m := filterCollisionKeyResults( m := filterCollisionKeyResults(
t, t,
ctx, ctx,
userID, userID,
cIDs[path.EmailCategory], containerIDs[cat],
GetItemsInContainerByCollisionKeyer[string](acMail), GetItemsInContainerByCollisionKeyer[string](ac),
collKeys[path.EmailCategory]) collisionKeys[cat])
maps.Copy(result, m) maps.Copy(result, m)
checkRestoreCounts(t, ctr3, 0, countItemsInRestore, 0) currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory])
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
assert.Equal(t, len(mailIDs), len(currentMailIDs), "count of ids are equal") assert.Equal(t, len(itemIDs[cat]), len(currentIDs), "count of ids are equal")
for orig := range mailIDs { for orig := range itemIDs[cat] {
assert.NotContains(t, currentMailIDs, orig, "original item should not exist after replacement") assert.NotContains(t, currentIDs, orig, "original item should not exist after replacement")
} }
mailIDs = currentMailIDs itemIDs[cat] = currentIDs
})
}
assert.Len(t, result, 0, "all items should have been replaced") assert.Len(t, result, 0, "all items should have been replaced")
}) })
@ -1226,45 +1182,35 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
} }
} }
assert.Len( assert.Len(t, filtEnts, countItemsInRestore, "every item should have been copied")
t,
filtEnts,
countItemsInRestore,
"every item should have been copied")
checkRestoreCounts(t, ctr4, 0, 0, countItemsInRestore) checkRestoreCounts(t, ctr4, 0, 0, countItemsInRestore)
result := filterCollisionKeyResults( result := map[string]string{}
t,
ctx,
userID,
cIDs[path.ContactsCategory],
GetItemsInContainerByCollisionKeyer[string](acCont),
collKeys[path.ContactsCategory])
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory]) for cat, ac := range testCategories {
require.NoError(t, err, clues.ToCore(err)) suite.Run(cat.String(), func() {
t := suite.T()
assert.Equal(t, 2*len(contactIDs), len(currentContactIDs), "count of ids should be double from before") ctx, flush := tester.NewContext(t)
assert.Subset(t, maps.Keys(currentContactIDs), maps.Keys(contactIDs), "original item should exist after copy") defer flush()
// m = checkCollisionKeyResults(t, ctx, userID, cIDs[path.EventsCategory], acEvts, collKeys[path.EventsCategory])
// maps.Copy(result, m)
m := filterCollisionKeyResults( m := filterCollisionKeyResults(
t, t,
ctx, ctx,
userID, userID,
cIDs[path.EmailCategory], containerIDs[cat],
GetItemsInContainerByCollisionKeyer[string](acMail), GetItemsInContainerByCollisionKeyer[string](ac),
collKeys[path.EmailCategory]) collisionKeys[cat])
maps.Copy(result, m) maps.Copy(result, m)
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory]) currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
assert.Equal(t, 2*len(mailIDs), len(currentMailIDs), "count of ids should be double from before") assert.Equal(t, 2*len(itemIDs[cat]), len(currentIDs), "count of ids should be double from before")
assert.Subset(t, maps.Keys(currentMailIDs), maps.Keys(mailIDs), "original item should exist after copy") assert.Subset(t, maps.Keys(currentIDs), maps.Keys(itemIDs[cat]), "original item should exist after copy")
})
}
// TODO: we have the option of modifying copy creations in exchange // TODO: we have the option of modifying copy creations in exchange
// so that the results don't collide. But we haven't made that // so that the results don't collide. But we haven't made that
@ -1344,7 +1290,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- contacts // --- contacts
cat := path.ContactsCategory cat := path.ContactsCategory
userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs( userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
t, t,
ctx, ctx,
acCont, acCont,
@ -1354,7 +1300,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- events // --- events
// cat = path.EventsCategory // cat = path.EventsCategory
// userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs( // userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
// t, // t,
// ctx, // ctx,
// acEvts, // acEvts,
@ -1364,7 +1310,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- mail // --- mail
cat = path.EmailCategory cat = path.EmailCategory
userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs( userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
t, t,
ctx, ctx,
acMail, acMail,
@ -1400,7 +1346,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- contacts // --- contacts
cat = path.ContactsCategory cat = path.ContactsCategory
secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs( secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
t, t,
ctx, ctx,
acCont, acCont,
@ -1410,7 +1356,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- events // --- events
// cat = path.EventsCategory // cat = path.EventsCategory
// secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs( // secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
// t, // t,
// ctx, // ctx,
// acEvts, // acEvts,
@ -1420,7 +1366,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
// --- mail // --- mail
cat = path.EmailCategory cat = path.EmailCategory
secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs( secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
t, t,
ctx, ctx,
acMail, acMail,
@ -1436,52 +1382,31 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
} }
} }
type GetItemsKeysAndContainerByNameer interface {
GetItemIDsInContainer(
ctx context.Context,
userID, containerID string,
) (map[string]struct{}, error)
GetContainerByName(
ctx context.Context,
userID, parentContainerID, containerName string,
) (graph.Container, error)
GetItemsInContainerByCollisionKey(
ctx context.Context,
userID, containerID string,
) (map[string]string, error)
}
func getCollKeysAndItemIDs( func getCollKeysAndItemIDs(
t *testing.T, t *testing.T,
ctx context.Context, //revive:disable-line:context-as-argument ctx context.Context, //revive:disable-line:context-as-argument
gikacbn GetItemsKeysAndContainerByNameer, cip clientItemPager,
userID, parentContainerID string, userID, parentContainerID string,
containerNames ...string, containerNames ...string,
) (map[string]struct{}, map[string]string) { ) (map[string]struct{}, map[string]string, string) {
var ( var (
c graph.Container c graph.Container
err error err error
cID string cID = parentContainerID
) )
for _, cn := range containerNames { for _, cn := range containerNames {
pcid := parentContainerID c, err = cip.GetContainerByName(ctx, userID, cID, cn)
if len(cID) != 0 {
pcid = cID
}
c, err = gikacbn.GetContainerByName(ctx, userID, pcid, cn)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
cID = ptr.Val(c.GetId()) cID = ptr.Val(c.GetId())
} }
itemIDs, err := gikacbn.GetItemIDsInContainer(ctx, userID, cID) itemIDs, err := cip.GetItemIDsInContainer(ctx, userID, cID)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
collisionKeys, err := gikacbn.GetItemsInContainerByCollisionKey(ctx, userID, cID) collisionKeys, err := cip.GetItemsInContainerByCollisionKey(ctx, userID, cID)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
return itemIDs, collisionKeys return itemIDs, collisionKeys, cID
} }