Update details merge function for details Builder and new location of folder population (#1926)
## Description Folder population now done when merging items in BackupOp. Also add more tests to make sure folders are actually populated properly in Details ## 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 - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🐹 Trivial/Minor ## Issue(s) * #1800 ## Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
c3dbd5e0a8
commit
62c8f8c6ea
@ -498,6 +498,9 @@ func mergeDetails(
|
||||
item,
|
||||
)
|
||||
|
||||
folders := details.FolderEntriesForPath(newPath.ToBuilder().Dir())
|
||||
deets.AddFoldersForItem(folders, item)
|
||||
|
||||
// Track how many entries we added so that we know if we got them all when
|
||||
// we're done.
|
||||
addedEntries++
|
||||
|
||||
@ -619,7 +619,7 @@ func makeManifest(backupID model.StableID, incompleteReason string) *snapshot.Ma
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *BackupOpSuite) TestBackupOperation_MergeBackupDetails() {
|
||||
func (suite *BackupOpSuite) TestBackupOperation_MergeBackupDetails_AddsItems() {
|
||||
var (
|
||||
tenant = "a-tenant"
|
||||
ro = "a-user"
|
||||
@ -1118,6 +1118,127 @@ func (suite *BackupOpSuite) TestBackupOperation_MergeBackupDetails() {
|
||||
}
|
||||
}
|
||||
|
||||
func makeFolderEntry(
|
||||
pb *path.Builder,
|
||||
size int64,
|
||||
modTime time.Time,
|
||||
) *details.DetailsEntry {
|
||||
return &details.DetailsEntry{
|
||||
RepoRef: pb.String(),
|
||||
ShortRef: pb.ShortRef(),
|
||||
ParentRef: pb.Dir().ShortRef(),
|
||||
ItemInfo: details.ItemInfo{
|
||||
Folder: &details.FolderInfo{
|
||||
ItemType: details.FolderItem,
|
||||
DisplayName: pb.Elements()[len(pb.Elements())-1],
|
||||
Modified: modTime,
|
||||
Size: size,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *BackupOpSuite) TestBackupOperation_MergeBackupDetails_AddsFolders() {
|
||||
var (
|
||||
t = suite.T()
|
||||
|
||||
tenant = "a-tenant"
|
||||
ro = "a-user"
|
||||
|
||||
pathElems = []string{
|
||||
tenant,
|
||||
path.ExchangeService.String(),
|
||||
ro,
|
||||
path.EmailCategory.String(),
|
||||
"work",
|
||||
"item1",
|
||||
}
|
||||
|
||||
itemPath1 = makePath(
|
||||
t,
|
||||
pathElems,
|
||||
true,
|
||||
)
|
||||
|
||||
backup1 = backup.Backup{
|
||||
BaseModel: model.BaseModel{
|
||||
ID: "bid1",
|
||||
},
|
||||
DetailsID: "did1",
|
||||
}
|
||||
|
||||
pathReason1 = kopia.Reason{
|
||||
ResourceOwner: itemPath1.ResourceOwner(),
|
||||
Service: itemPath1.Service(),
|
||||
Category: itemPath1.Category(),
|
||||
}
|
||||
|
||||
inputToMerge = map[string]path.Path{
|
||||
itemPath1.ShortRef(): itemPath1,
|
||||
}
|
||||
|
||||
inputMans = []*kopia.ManifestEntry{
|
||||
{
|
||||
Manifest: makeManifest(backup1.ID, ""),
|
||||
Reasons: []kopia.Reason{
|
||||
pathReason1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
populatedModels = map[model.StableID]backup.Backup{
|
||||
backup1.ID: backup1,
|
||||
}
|
||||
|
||||
itemSize = 42
|
||||
itemDetails = makeDetailsEntry(t, itemPath1, itemSize, false)
|
||||
|
||||
populatedDetails = map[string]*details.Details{
|
||||
backup1.DetailsID: {
|
||||
DetailsModel: details.DetailsModel{
|
||||
Entries: []details.DetailsEntry{
|
||||
*itemDetails,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expectedEntries = []details.DetailsEntry{
|
||||
*itemDetails,
|
||||
}
|
||||
)
|
||||
|
||||
itemDetails.Exchange.Modified = time.Now()
|
||||
|
||||
for i := 1; i < len(pathElems); i++ {
|
||||
expectedEntries = append(expectedEntries, *makeFolderEntry(
|
||||
path.Builder{}.Append(pathElems[:i]...),
|
||||
int64(itemSize),
|
||||
itemDetails.Exchange.Modified,
|
||||
))
|
||||
}
|
||||
|
||||
ctx, flush := tester.NewContext()
|
||||
defer flush()
|
||||
|
||||
mdr := mockDetailsReader{entries: populatedDetails}
|
||||
w := &store.Wrapper{Storer: mockBackupStorer{entries: populatedModels}}
|
||||
|
||||
deets := details.Builder{}
|
||||
|
||||
err := mergeDetails(
|
||||
ctx,
|
||||
w,
|
||||
mdr,
|
||||
inputMans,
|
||||
inputToMerge,
|
||||
&deets,
|
||||
)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, expectedEntries, deets.Details().Entries)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// integration
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -142,6 +142,7 @@ func FolderEntriesForPath(parent *path.Builder) []FolderEntry {
|
||||
ParentRef: nextParent.ShortRef(),
|
||||
Info: ItemInfo{
|
||||
Folder: &FolderInfo{
|
||||
ItemType: FolderItem,
|
||||
DisplayName: parent.Elements()[len(parent.Elements())-1],
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user