Make order insensitive permission compare (#2448)
## Description Update the comparison for OneDrive permissions so it doesn't assume a fixed order. Also fix index out of bounds errors if backup did not retrieve the expected permissions ## 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) * #2447 ## Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
47d0eeb700
commit
754981d0d2
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/mockconnector"
|
"github.com/alcionai/corso/src/internal/connector/mockconnector"
|
||||||
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
||||||
@ -652,6 +653,35 @@ func compareExchangeEvent(
|
|||||||
checkEvent(t, expectedEvent, itemEvent)
|
checkEvent(t, expectedEvent, itemEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func permissionEqual(expected onedrive.UserPermission, got onedrive.UserPermission) bool {
|
||||||
|
if !strings.EqualFold(expected.Email, got.Email) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expected.Expiration == nil && got.Expiration != nil) ||
|
||||||
|
(expected.Expiration != nil && got.Expiration == nil) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected.Expiration != nil &&
|
||||||
|
got.Expiration != nil &&
|
||||||
|
!expected.Expiration.Equal(*got.Expiration) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(expected.Roles) != len(got.Roles) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range got.Roles {
|
||||||
|
if !slices.Contains(expected.Roles, r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func compareOneDriveItem(
|
func compareOneDriveItem(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
expected map[string][]byte,
|
expected map[string][]byte,
|
||||||
@ -695,13 +725,7 @@ func compareOneDriveItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, len(expectedMeta.Permissions), len(itemMeta.Permissions), "number of permissions after restore")
|
assert.Equal(t, len(expectedMeta.Permissions), len(itemMeta.Permissions), "number of permissions after restore")
|
||||||
|
testElementsMatch(t, expectedMeta.Permissions, itemMeta.Permissions, permissionEqual)
|
||||||
// FIXME(meain): The permissions before and after might not be in the same order.
|
|
||||||
for i, p := range expectedMeta.Permissions {
|
|
||||||
assert.Equal(t, strings.ToLower(p.Email), strings.ToLower(itemMeta.Permissions[i].Email))
|
|
||||||
assert.Equal(t, p.Roles, itemMeta.Permissions[i].Roles)
|
|
||||||
assert.Equal(t, p.Expiration, itemMeta.Permissions[i].Expiration)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareItem(
|
func compareItem(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user