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:
parent
a973f69d18
commit
34d6c18d74
@ -889,6 +889,26 @@ func (suite *ExchangeRestoreIntgSuite) SetupSuite() {
|
||||
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() {
|
||||
t := suite.T()
|
||||
|
||||
@ -921,25 +941,28 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
var (
|
||||
restoreCfg = ctrlTD.DefaultRestoreConfig("exchange_adv_restore")
|
||||
sel = rsel.Selector
|
||||
userID = sel.ID()
|
||||
cIDs = map[path.CategoryType]string{
|
||||
path.ContactsCategory: "",
|
||||
path.EmailCategory: "",
|
||||
path.EventsCategory: "",
|
||||
restoreCfg = ctrlTD.DefaultRestoreConfig("exchange_adv_restore")
|
||||
sel = rsel.Selector
|
||||
userID = sel.ID()
|
||||
countItemsInRestore int
|
||||
|
||||
itemIDs = map[path.CategoryType]map[string]struct{}{}
|
||||
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(),
|
||||
}
|
||||
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
|
||||
// countEventsInRestore int
|
||||
// acEvts = suite.its.ac.Events()
|
||||
// eventIDs = []string{}
|
||||
)
|
||||
|
||||
// initial restore
|
||||
@ -971,61 +994,27 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
|
||||
// get all files in folder, use these as the base
|
||||
// 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)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
cIDs[path.ContactsCategory] = ptr.Val(contGC.GetId())
|
||||
containers := append([]string{restoreCfg.Location}, parentContainerNames[cat]...)
|
||||
|
||||
collKeys[path.ContactsCategory], err = acCont.GetItemsInContainerByCollisionKey(
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.ContactsCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
countContactsInRestore = len(collKeys[path.ContactsCategory])
|
||||
t.Log(countContactsInRestore, "contacts restored")
|
||||
itemIDs[cat], collisionKeys[cat], containerIDs[cat] = getCollKeysAndItemIDs(
|
||||
t,
|
||||
ctx,
|
||||
ac,
|
||||
userID,
|
||||
parentContainerIDs[cat],
|
||||
containers...)
|
||||
|
||||
contactIDs, err = acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
countItemsInRestore += len(collisionKeys[cat])
|
||||
})
|
||||
}
|
||||
|
||||
// --- 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)
|
||||
})
|
||||
|
||||
@ -1062,43 +1051,30 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
|
||||
|
||||
checkRestoreCounts(t, ctr2, countItemsInRestore, 0, 0)
|
||||
|
||||
// --- contacts
|
||||
result := map[string]string{}
|
||||
|
||||
// get all files in folder, use these as the base
|
||||
// set of files to compare against.
|
||||
result := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.ContactsCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acCont),
|
||||
collKeys[path.ContactsCategory])
|
||||
for cat, ac := range testCategories {
|
||||
suite.Run(cat.String(), func() {
|
||||
t := suite.T()
|
||||
|
||||
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
assert.Equal(t, contactIDs, currentContactIDs, "ids are equal")
|
||||
m := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
containerIDs[cat],
|
||||
GetItemsInContainerByCollisionKeyer[string](ac),
|
||||
collisionKeys[cat])
|
||||
maps.Copy(result, m)
|
||||
|
||||
// --- events
|
||||
currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
// m = checkCollisionKeyResults(t, ctx, userID, cIDs[path.EventsCategory], acEvts, collKeys[path.EventsCategory])
|
||||
// maps.Copy(result, m)
|
||||
|
||||
// --- mail
|
||||
|
||||
m := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.EmailCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acMail),
|
||||
collKeys[path.EmailCategory])
|
||||
maps.Copy(result, m)
|
||||
|
||||
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory])
|
||||
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")
|
||||
})
|
||||
@ -1136,60 +1112,40 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
|
||||
}
|
||||
}
|
||||
|
||||
assert.Len(
|
||||
t,
|
||||
filtEnts,
|
||||
countItemsInRestore,
|
||||
"every item should have been replaced")
|
||||
|
||||
// --- contacts
|
||||
|
||||
result := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.ContactsCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acCont),
|
||||
collKeys[path.ContactsCategory])
|
||||
|
||||
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
assert.Equal(t, len(contactIDs), len(currentContactIDs), "count of ids are equal")
|
||||
for orig := range contactIDs {
|
||||
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(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.EmailCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acMail),
|
||||
collKeys[path.EmailCategory])
|
||||
maps.Copy(result, m)
|
||||
assert.Len(t, filtEnts, countItemsInRestore, "every item should have been replaced")
|
||||
|
||||
checkRestoreCounts(t, ctr3, 0, countItemsInRestore, 0)
|
||||
|
||||
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
result := map[string]string{}
|
||||
|
||||
assert.Equal(t, len(mailIDs), len(currentMailIDs), "count of ids are equal")
|
||||
for orig := range mailIDs {
|
||||
assert.NotContains(t, currentMailIDs, orig, "original item should not exist after replacement")
|
||||
for cat, ac := range testCategories {
|
||||
suite.Run(cat.String(), func() {
|
||||
t := suite.T()
|
||||
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
m := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
containerIDs[cat],
|
||||
GetItemsInContainerByCollisionKeyer[string](ac),
|
||||
collisionKeys[cat])
|
||||
maps.Copy(result, m)
|
||||
|
||||
currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
assert.Equal(t, len(itemIDs[cat]), len(currentIDs), "count of ids are equal")
|
||||
for orig := range itemIDs[cat] {
|
||||
assert.NotContains(t, currentIDs, orig, "original item should not exist after replacement")
|
||||
}
|
||||
|
||||
itemIDs[cat] = currentIDs
|
||||
})
|
||||
}
|
||||
|
||||
mailIDs = currentMailIDs
|
||||
|
||||
assert.Len(t, result, 0, "all items should have been replaced")
|
||||
})
|
||||
|
||||
@ -1226,45 +1182,35 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
|
||||
}
|
||||
}
|
||||
|
||||
assert.Len(
|
||||
t,
|
||||
filtEnts,
|
||||
countItemsInRestore,
|
||||
"every item should have been copied")
|
||||
assert.Len(t, filtEnts, countItemsInRestore, "every item should have been copied")
|
||||
|
||||
checkRestoreCounts(t, ctr4, 0, 0, countItemsInRestore)
|
||||
|
||||
result := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.ContactsCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acCont),
|
||||
collKeys[path.ContactsCategory])
|
||||
result := map[string]string{}
|
||||
|
||||
currentContactIDs, err := acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
for cat, ac := range testCategories {
|
||||
suite.Run(cat.String(), func() {
|
||||
t := suite.T()
|
||||
|
||||
assert.Equal(t, 2*len(contactIDs), len(currentContactIDs), "count of ids should be double from before")
|
||||
assert.Subset(t, maps.Keys(currentContactIDs), maps.Keys(contactIDs), "original item should exist after copy")
|
||||
ctx, flush := tester.NewContext(t)
|
||||
defer flush()
|
||||
|
||||
// m = checkCollisionKeyResults(t, ctx, userID, cIDs[path.EventsCategory], acEvts, collKeys[path.EventsCategory])
|
||||
// maps.Copy(result, m)
|
||||
m := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
containerIDs[cat],
|
||||
GetItemsInContainerByCollisionKeyer[string](ac),
|
||||
collisionKeys[cat])
|
||||
maps.Copy(result, m)
|
||||
|
||||
m := filterCollisionKeyResults(
|
||||
t,
|
||||
ctx,
|
||||
userID,
|
||||
cIDs[path.EmailCategory],
|
||||
GetItemsInContainerByCollisionKeyer[string](acMail),
|
||||
collKeys[path.EmailCategory])
|
||||
maps.Copy(result, m)
|
||||
currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory])
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
assert.Equal(t, 2*len(mailIDs), len(currentMailIDs), "count of ids should be double from before")
|
||||
assert.Subset(t, maps.Keys(currentMailIDs), maps.Keys(mailIDs), "original item should exist after copy")
|
||||
assert.Equal(t, 2*len(itemIDs[cat]), len(currentIDs), "count of ids should be double from before")
|
||||
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
|
||||
// so that the results don't collide. But we haven't made that
|
||||
@ -1344,7 +1290,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- contacts
|
||||
cat := path.ContactsCategory
|
||||
userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
t,
|
||||
ctx,
|
||||
acCont,
|
||||
@ -1354,7 +1300,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- events
|
||||
// cat = path.EventsCategory
|
||||
// userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
// userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
// t,
|
||||
// ctx,
|
||||
// acEvts,
|
||||
@ -1364,7 +1310,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- mail
|
||||
cat = path.EmailCategory
|
||||
userItemIDs[cat], userCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
userItemIDs[cat], userCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
t,
|
||||
ctx,
|
||||
acMail,
|
||||
@ -1400,7 +1346,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- contacts
|
||||
cat = path.ContactsCategory
|
||||
secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
t,
|
||||
ctx,
|
||||
acCont,
|
||||
@ -1410,7 +1356,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- events
|
||||
// cat = path.EventsCategory
|
||||
// secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
// secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
// t,
|
||||
// ctx,
|
||||
// acEvts,
|
||||
@ -1420,7 +1366,7 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeAlternateProtecte
|
||||
|
||||
// --- mail
|
||||
cat = path.EmailCategory
|
||||
secondaryItemIDs[cat], secondaryCollisionKeys[cat] = getCollKeysAndItemIDs(
|
||||
secondaryItemIDs[cat], secondaryCollisionKeys[cat], _ = getCollKeysAndItemIDs(
|
||||
t,
|
||||
ctx,
|
||||
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(
|
||||
t *testing.T,
|
||||
ctx context.Context, //revive:disable-line:context-as-argument
|
||||
gikacbn GetItemsKeysAndContainerByNameer,
|
||||
cip clientItemPager,
|
||||
userID, parentContainerID string,
|
||||
containerNames ...string,
|
||||
) (map[string]struct{}, map[string]string) {
|
||||
) (map[string]struct{}, map[string]string, string) {
|
||||
var (
|
||||
c graph.Container
|
||||
err error
|
||||
cID string
|
||||
cID = parentContainerID
|
||||
)
|
||||
|
||||
for _, cn := range containerNames {
|
||||
pcid := parentContainerID
|
||||
|
||||
if len(cID) != 0 {
|
||||
pcid = cID
|
||||
}
|
||||
|
||||
c, err = gikacbn.GetContainerByName(ctx, userID, pcid, cn)
|
||||
c, err = cip.GetContainerByName(ctx, userID, cID, cn)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
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))
|
||||
|
||||
collisionKeys, err := gikacbn.GetItemsInContainerByCollisionKey(ctx, userID, cID)
|
||||
collisionKeys, err := cip.GetItemsInContainerByCollisionKey(ctx, userID, cID)
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
return itemIDs, collisionKeys
|
||||
return itemIDs, collisionKeys, cID
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user