Return map instead of using in-out param (#3308)
Return type should really be switched to []data.BackupCollection but that's a non-trivial change to make since tests rely on being able to lookup things by folder ID. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
e67e5be977
commit
f5365f19c5
@ -277,9 +277,6 @@ func createCollections(
|
|||||||
return nil, clues.Stack(err).WithClues(ctx)
|
return nil, clues.Stack(err).WithClues(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create collection of ExchangeDataCollection
|
|
||||||
collections := make(map[string]data.BackupCollection)
|
|
||||||
|
|
||||||
qp := graph.QueryParams{
|
qp := graph.QueryParams{
|
||||||
Category: category,
|
Category: category,
|
||||||
ResourceOwner: user,
|
ResourceOwner: user,
|
||||||
@ -297,11 +294,10 @@ func createCollections(
|
|||||||
return nil, clues.Wrap(err, "populating container cache")
|
return nil, clues.Wrap(err, "populating container cache")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = filterContainersAndFillCollections(
|
collections, err := filterContainersAndFillCollections(
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
getter,
|
getter,
|
||||||
collections,
|
|
||||||
su,
|
su,
|
||||||
resolver,
|
resolver,
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
@ -31,19 +31,24 @@ type addedAndRemovedItemIDsGetter interface {
|
|||||||
// into a BackupCollection. Messages outside of those directories are omitted.
|
// into a BackupCollection. Messages outside of those directories are omitted.
|
||||||
// @param collection is filled with during this function.
|
// @param collection is filled with during this function.
|
||||||
// Supports all exchange applications: Contacts, Events, and Mail
|
// Supports all exchange applications: Contacts, Events, and Mail
|
||||||
|
//
|
||||||
|
// TODO(ashmrtn): This should really return []data.BackupCollection but
|
||||||
|
// unfortunately some of our tests rely on being able to lookup returned
|
||||||
|
// collections by ID and it would be non-trivial to change them.
|
||||||
func filterContainersAndFillCollections(
|
func filterContainersAndFillCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
qp graph.QueryParams,
|
qp graph.QueryParams,
|
||||||
getter addedAndRemovedItemIDsGetter,
|
getter addedAndRemovedItemIDsGetter,
|
||||||
collections map[string]data.BackupCollection,
|
|
||||||
statusUpdater support.StatusUpdater,
|
statusUpdater support.StatusUpdater,
|
||||||
resolver graph.ContainerResolver,
|
resolver graph.ContainerResolver,
|
||||||
scope selectors.ExchangeScope,
|
scope selectors.ExchangeScope,
|
||||||
dps DeltaPaths,
|
dps DeltaPaths,
|
||||||
ctrlOpts control.Options,
|
ctrlOpts control.Options,
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
) error {
|
) (map[string]data.BackupCollection, error) {
|
||||||
var (
|
var (
|
||||||
|
// folder ID -> BackupCollection.
|
||||||
|
collections = map[string]data.BackupCollection{}
|
||||||
// folder ID -> delta url or folder path lookups
|
// folder ID -> delta url or folder path lookups
|
||||||
deltaURLs = map[string]string{}
|
deltaURLs = map[string]string{}
|
||||||
currPaths = map[string]string{}
|
currPaths = map[string]string{}
|
||||||
@ -64,19 +69,19 @@ func filterContainersAndFillCollections(
|
|||||||
// But this will work for the short term.
|
// But this will work for the short term.
|
||||||
ac, err := api.NewClient(qp.Credentials)
|
ac, err := api.NewClient(qp.Credentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ibt, err := itemerByType(ac, category)
|
ibt, err := itemerByType(ac, category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
el := errs.Local()
|
el := errs.Local()
|
||||||
|
|
||||||
for _, c := range resolver.Items() {
|
for _, c := range resolver.Items() {
|
||||||
if el.Failure() != nil {
|
if el.Failure() != nil {
|
||||||
return el.Failure()
|
return nil, el.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
cID := ptr.Val(c.GetId())
|
cID := ptr.Val(c.GetId())
|
||||||
@ -222,7 +227,7 @@ func filterContainersAndFillCollections(
|
|||||||
// resolver (which contains all the resource owners' current containers).
|
// resolver (which contains all the resource owners' current containers).
|
||||||
for id, p := range tombstones {
|
for id, p := range tombstones {
|
||||||
if el.Failure() != nil {
|
if el.Failure() != nil {
|
||||||
return el.Failure()
|
return nil, el.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
ictx := clues.Add(ctx, "tombstone_id", id)
|
ictx := clues.Add(ctx, "tombstone_id", id)
|
||||||
@ -274,12 +279,12 @@ func filterContainersAndFillCollections(
|
|||||||
},
|
},
|
||||||
statusUpdater)
|
statusUpdater)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return clues.Wrap(err, "making metadata collection")
|
return nil, clues.Wrap(err, "making metadata collection")
|
||||||
}
|
}
|
||||||
|
|
||||||
collections["metadata"] = col
|
collections["metadata"] = col
|
||||||
|
|
||||||
return el.Failure()
|
return collections, el.Failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
// produces a set of id:path pairs from the deltapaths map.
|
// produces a set of id:path pairs from the deltapaths map.
|
||||||
|
|||||||
@ -287,13 +287,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections() {
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections, err := filterContainersAndFillCollections(
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
test.getter,
|
test.getter,
|
||||||
collections,
|
|
||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
test.scope,
|
test.scope,
|
||||||
@ -629,13 +626,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_Dupli
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections, err := filterContainersAndFillCollections(
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
test.getter,
|
test.getter,
|
||||||
collections,
|
|
||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
sc.scope,
|
sc.scope,
|
||||||
@ -878,13 +872,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_Dupli
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections, err := filterContainersAndFillCollections(
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
test.getter,
|
test.getter,
|
||||||
collections,
|
|
||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
scope,
|
scope,
|
||||||
@ -1033,13 +1024,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_repea
|
|||||||
require.Equal(t, "user_id", qp.ResourceOwner.ID(), qp.ResourceOwner)
|
require.Equal(t, "user_id", qp.ResourceOwner.ID(), qp.ResourceOwner)
|
||||||
require.Equal(t, "user_name", qp.ResourceOwner.Name(), qp.ResourceOwner)
|
require.Equal(t, "user_name", qp.ResourceOwner.Name(), qp.ResourceOwner)
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections, err := filterContainersAndFillCollections(
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
test.getter,
|
test.getter,
|
||||||
collections,
|
|
||||||
statusUpdater,
|
statusUpdater,
|
||||||
resolver,
|
resolver,
|
||||||
allScope,
|
allScope,
|
||||||
@ -1398,13 +1386,10 @@ func (suite *ServiceIteratorsSuite) TestFilterContainersAndFillCollections_incre
|
|||||||
ctx, flush := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
collections := map[string]data.BackupCollection{}
|
collections, err := filterContainersAndFillCollections(
|
||||||
|
|
||||||
err := filterContainersAndFillCollections(
|
|
||||||
ctx,
|
ctx,
|
||||||
qp,
|
qp,
|
||||||
test.getter,
|
test.getter,
|
||||||
collections,
|
|
||||||
statusUpdater,
|
statusUpdater,
|
||||||
test.resolver,
|
test.resolver,
|
||||||
allScope,
|
allScope,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user