clean up exchange adv restore test

This commit is contained in:
ryanfkeepers 2023-07-20 18:36:32 -06:00
parent effecdd290
commit 5efbd966fd

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()
@ -921,25 +941,23 @@ func (suite *ExchangeRestoreIntgSuite) TestRestore_Run_exchangeWithAdvancedOptio
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
var ( var (
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{ countItemsInRestore int
path.ContactsCategory: "",
path.EmailCategory: "", itemIDs = map[path.CategoryType]map[string]struct{}{}
path.EventsCategory: "", collisionKeys = map[path.CategoryType]map[string]string{}
containerIDs = map[path.CategoryType]string{}
parentContainerIDs = map[path.CategoryType]string{
path.EmailCategory: api.MsgFolderRoot,
}
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 // initial restore
@ -971,61 +989,26 @@ 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()) itemIDs[cat], collisionKeys[cat], containerIDs[cat] = getCollKeysAndItemIDs(
t,
ctx,
ac,
userID,
parentContainerIDs[cat],
restoreCfg.Location)
})
}
collKeys[path.ContactsCategory], err = acCont.GetItemsInContainerByCollisionKey( countItemsInRestore = len(collisionKeys[path.ContactsCategory]) +
ctx, len(collisionKeys[path.EmailCategory]) +
userID, len(collisionKeys[path.EventsCategory])
cIDs[path.ContactsCategory])
require.NoError(t, err, clues.ToCore(err))
countContactsInRestore = len(collKeys[path.ContactsCategory])
t.Log(countContactsInRestore, "contacts restored")
contactIDs, err = acCont.GetItemIDsInContainer(ctx, userID, cIDs[path.ContactsCategory])
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 +1045,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") 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]) assert.Equal(t, itemIDs[cat], currentIDs, "ids are equal")
// 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.Len(t, result, 0, "no new items should get added") assert.Len(t, result, 0, "no new items should get added")
}) })
@ -1136,60 +1106,40 @@ 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
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)
checkRestoreCounts(t, ctr3, 0, countItemsInRestore, 0) checkRestoreCounts(t, ctr3, 0, countItemsInRestore, 0)
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory]) result := map[string]string{}
require.NoError(t, err, clues.ToCore(err))
assert.Equal(t, len(mailIDs), len(currentMailIDs), "count of ids are equal") for cat, ac := range testCategories {
for orig := range mailIDs { suite.Run(cat.String(), func() {
assert.NotContains(t, currentMailIDs, orig, "original item should not exist after replacement") 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") assert.Len(t, result, 0, "all items should have been replaced")
}) })
@ -1226,45 +1176,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]) m := filterCollisionKeyResults(
// maps.Copy(result, m) t,
ctx,
userID,
containerIDs[cat],
GetItemsInContainerByCollisionKeyer[string](ac),
collisionKeys[cat])
maps.Copy(result, m)
m := filterCollisionKeyResults( currentIDs, err := ac.GetItemIDsInContainer(ctx, userID, containerIDs[cat])
t, require.NoError(t, err, clues.ToCore(err))
ctx,
userID,
cIDs[path.EmailCategory],
GetItemsInContainerByCollisionKeyer[string](acMail),
collKeys[path.EmailCategory])
maps.Copy(result, m)
currentMailIDs, err := acMail.GetItemIDsInContainer(ctx, userID, cIDs[path.EmailCategory]) assert.Equal(t, 2*len(itemIDs[cat]), len(currentIDs), "count of ids should be double from before")
require.NoError(t, err, clues.ToCore(err)) assert.Subset(t, maps.Keys(currentIDs), maps.Keys(itemIDs[cat]), "original item should exist after copy")
})
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")
// 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 +1284,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 +1294,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 +1304,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 +1340,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 +1350,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 +1360,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,28 +1376,13 @@ 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
@ -1471,17 +1396,17 @@ func getCollKeysAndItemIDs(
pcid = cID pcid = cID
} }
c, err = gikacbn.GetContainerByName(ctx, userID, pcid, cn) c, err = cip.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
} }