OneDrive test framework (#2533)
## Description Major changes: * OneDrive files now store the lookup key in the first few bytes of the file and then the file data. This allows the test framework to continue working even when we switch to using item IDs as names * Create a framework to create the data necessary for testing. This framework uses something akin to the builder pattern and automatically adds files to the collection if they should appear in that version. For example, trying to add a metadata file to a backup version that didn't have metadata files will result in a noop. Adding files will also add the metadata to the aux file set Long term this will hopefully make ensuring compatibility between OneDrive versions easier because only a few places in the code need to be updated to support another version. It also allows easy ranges over different versions via for-loop ## 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 - [x] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup ## Issue(s) * #1535 ## Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
19dad32db9
commit
6e0b9183b4
@ -191,7 +191,6 @@ type restoreBackupInfo struct {
|
||||
}
|
||||
|
||||
type restoreBackupInfoMultiVersion struct {
|
||||
name string
|
||||
service path.ServiceType
|
||||
collectionsLatest []colInfo
|
||||
collectionsPrevious []colInfo
|
||||
@ -707,43 +706,78 @@ func compareOneDriveItem(
|
||||
item data.Stream,
|
||||
restorePermissions bool,
|
||||
) {
|
||||
name := item.UUID()
|
||||
|
||||
expectedData := expected[item.UUID()]
|
||||
if !assert.NotNil(t, expectedData, "unexpected file with name %s", item.UUID()) {
|
||||
return
|
||||
}
|
||||
|
||||
buf, err := io.ReadAll(item.ToReader())
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(name, onedrive.MetaFileSuffix) && !strings.HasSuffix(name, onedrive.DirMetaFileSuffix) {
|
||||
// OneDrive data items are just byte buffers of the data. Nothing special to
|
||||
// interpret. May need to do chunked comparisons in the future if we test
|
||||
// large item equality.
|
||||
assert.Equal(t, expectedData, buf)
|
||||
name := item.UUID()
|
||||
if strings.HasSuffix(name, onedrive.MetaFileSuffix) ||
|
||||
strings.HasSuffix(name, onedrive.DirMetaFileSuffix) {
|
||||
var (
|
||||
itemMeta onedrive.Metadata
|
||||
expectedMeta onedrive.Metadata
|
||||
)
|
||||
|
||||
err = json.Unmarshal(buf, &itemMeta)
|
||||
if !assert.NoErrorf(t, err, "unmarshalling retrieved metadata for file %s", name) {
|
||||
return
|
||||
}
|
||||
|
||||
expectedData := expected[name]
|
||||
if !assert.NotNil(
|
||||
t,
|
||||
expectedData,
|
||||
"unexpected metadata file with name %s",
|
||||
name,
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(expectedData, &expectedMeta)
|
||||
if !assert.NoError(t, err, "unmarshalling expected metadata") {
|
||||
return
|
||||
}
|
||||
|
||||
// Only compare file names if we're using a version that expects them to be
|
||||
// set.
|
||||
if len(expectedMeta.FileName) > 0 {
|
||||
assert.Equal(t, expectedMeta.FileName, itemMeta.FileName)
|
||||
}
|
||||
|
||||
if !restorePermissions {
|
||||
assert.Equal(t, 0, len(itemMeta.Permissions))
|
||||
return
|
||||
}
|
||||
|
||||
testElementsMatch(
|
||||
t,
|
||||
expectedMeta.Permissions,
|
||||
itemMeta.Permissions,
|
||||
permissionEqual,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
itemMeta onedrive.Metadata
|
||||
expectedMeta onedrive.Metadata
|
||||
)
|
||||
var fileData testOneDriveData
|
||||
|
||||
err = json.Unmarshal(buf, &itemMeta)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = json.Unmarshal(expectedData, &expectedMeta)
|
||||
assert.Nil(t, err)
|
||||
|
||||
if !restorePermissions {
|
||||
assert.Equal(t, 0, len(itemMeta.Permissions))
|
||||
err = json.Unmarshal(buf, &fileData)
|
||||
if !assert.NoErrorf(t, err, "unmarshalling file data for file %s", name) {
|
||||
return
|
||||
}
|
||||
|
||||
testElementsMatch(t, expectedMeta.Permissions, itemMeta.Permissions, permissionEqual)
|
||||
expectedData := expected[fileData.FileName]
|
||||
if !assert.NotNil(t, expectedData, "unexpected file with name %s", name) {
|
||||
return
|
||||
}
|
||||
|
||||
// OneDrive data items are just byte buffers of the data. Nothing special to
|
||||
// interpret. May need to do chunked comparisons in the future if we test
|
||||
// large item equality.
|
||||
// Compare against the version with the file name embedded because that's what
|
||||
// the auto-generated expected data has.
|
||||
assert.Equal(t, expectedData, buf)
|
||||
}
|
||||
|
||||
func compareItem(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user