Add basic RestoreAndBackup test for SharePoint (#2935)

Reuses a lot of the OneDrive logic to run
the test. Only tests basic things as it's
assuming the OneDrive set of tests will do
a more thorough job testing the overall
logic for backup/restore and permissions

Doesn't test permissions as those aren't
yet enabled for SharePoint

---

#### 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] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #2897

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-03-27 15:41:50 -07:00 committed by GitHub
parent f9654ce994
commit 1548d51004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 306 additions and 137 deletions

View File

@ -745,11 +745,20 @@ func compareOneDriveItem(
strings.HasSuffix(name, onedrive.DirMetaFileSuffix)
if isMeta {
_, ok := item.(*onedrive.MetadataItem)
assert.True(t, ok, "metadata item")
var itemType *onedrive.MetadataItem
assert.IsType(t, itemType, item)
} else {
oitem := item.(*onedrive.Item)
info := oitem.Info()
// Don't need to check SharePoint because it was added after we stopped
// adding meta files to backup details.
if info.OneDrive != nil {
assert.False(t, oitem.Info().OneDrive.IsMeta, "meta marker for non meta item %s", name)
} else if info.SharePoint == nil {
assert.Fail(t, "ItemInfo is not SharePoint or OneDrive")
}
}
if isMeta {
@ -763,12 +772,14 @@ func compareOneDriveItem(
return true
}
expectedData := expected[name]
key := name
if strings.HasSuffix(name, onedrive.MetaFileSuffix) {
expectedData = expected[itemMeta.FileName]
key = itemMeta.FileName
}
expectedData := expected[key]
if !assert.NotNil(
t,
expectedData,
@ -868,6 +879,14 @@ func compareItem(
case path.OneDriveService:
return compareOneDriveItem(t, expected, item, restorePermissions, rootDir)
case path.SharePointService:
if category != path.LibrariesCategory {
assert.FailNowf(t, "unsupported SharePoint category: %s", category.String())
}
// SharePoint libraries reuses OneDrive code.
return compareOneDriveItem(t, expected, item, restorePermissions, rootDir)
default:
assert.FailNowf(t, "unexpected service: %s", service.String())
}
@ -1038,6 +1057,38 @@ func makeOneDriveBackupSel(
return sel.Selector
}
func makeSharePointBackupSel(
t *testing.T,
dests []destAndCats,
) selectors.Selector {
toInclude := [][]selectors.SharePointScope{}
resourceOwners := map[string]struct{}{}
for _, d := range dests {
for c := range d.cats {
if c != path.LibrariesCategory {
assert.FailNowf(t, "unsupported category type %s", c.String())
}
resourceOwners[d.resourceOwner] = struct{}{}
// nil owners here, we'll need to stitch this together
// below after the loops are complete.
sel := selectors.NewSharePointBackup(nil)
toInclude = append(toInclude, sel.LibraryFolders(
[]string{d.dest},
selectors.PrefixMatch(),
))
}
}
sel := selectors.NewSharePointBackup(maps.Keys(resourceOwners))
sel.Include(toInclude...)
return sel.Selector
}
// backupSelectorForExpected creates a selector that can be used to backup the
// given items in expected based on the item paths. Fails the test if items from
// multiple services are in expected.
@ -1055,6 +1106,9 @@ func backupSelectorForExpected(
case path.OneDriveService:
return makeOneDriveBackupSel(t, dests)
case path.SharePointService:
return makeSharePointBackupSel(t, dests)
default:
assert.FailNow(t, "unknown service type %s", service.String())
}
@ -1075,7 +1129,7 @@ func backupOutputPathFromRestore(
base := []string{restoreDest.ContainerName}
// OneDrive has leading information like the drive ID.
if inputPath.Service() == path.OneDriveService {
if inputPath.Service() == path.OneDriveService || inputPath.Service() == path.SharePointService {
folders := inputPath.Folders()
base = append(append([]string{}, folders[:3]...), restoreDest.ContainerName)
@ -1159,11 +1213,14 @@ func collectionsForInfo(
baseExpected[info.items[i].lookupKey] = info.items[i].data
// We do not count metadata files against item count
if backupVersion == 0 || service != path.OneDriveService ||
(service == path.OneDriveService &&
strings.HasSuffix(info.items[i].name, onedrive.DataFileSuffix)) {
totalItems++
if backupVersion > 0 &&
(service == path.OneDriveService || service == path.SharePointService) &&
(strings.HasSuffix(info.items[i].name, onedrive.MetaFileSuffix) ||
strings.HasSuffix(info.items[i].name, onedrive.DirMetaFileSuffix)) {
continue
}
totalItems++
}
c := mockRestoreCollection{Collection: mc, auxItems: map[string]data.Stream{}}

View File

@ -1,12 +1,14 @@
package connector
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"testing"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
@ -117,10 +119,12 @@ var (
func newOneDriveCollection(
t *testing.T,
service path.ServiceType,
pathElements []string,
backupVersion int,
) *onedriveCollection {
return &onedriveCollection{
service: service,
pathElements: pathElements,
backupVersion: backupVersion,
t: t,
@ -128,6 +132,7 @@ func newOneDriveCollection(
}
type onedriveCollection struct {
service path.ServiceType
pathElements []string
items []itemInfo
aux []itemInfo
@ -136,9 +141,14 @@ type onedriveCollection struct {
}
func (c onedriveCollection) collection() colInfo {
cat := path.FilesCategory
if c.service == path.SharePointService {
cat = path.LibrariesCategory
}
return colInfo{
pathElements: c.pathElements,
category: path.FilesCategory,
category: cat,
items: c.items,
auxItems: c.aux,
}
@ -276,11 +286,16 @@ type onedriveColInfo struct {
folders []itemData
}
func testDataForInfo(t *testing.T, cols []onedriveColInfo, backupVersion int) []colInfo {
func testDataForInfo(
t *testing.T,
service path.ServiceType,
cols []onedriveColInfo,
backupVersion int,
) []colInfo {
var res []colInfo
for _, c := range cols {
onedriveCol := newOneDriveCollection(t, c.pathElements, backupVersion)
onedriveCol := newOneDriveCollection(t, service, c.pathElements, backupVersion)
for _, f := range c.files {
onedriveCol.withFile(f.name, f.data, f.perms)
@ -298,24 +313,166 @@ func testDataForInfo(t *testing.T, cols []onedriveColInfo, backupVersion int) []
return res
}
type oneDriveSuite interface {
tester.Suite
func mustGetDefaultDriveID(
t *testing.T,
ctx context.Context, //revive:disable-line:context-as-argument
backupService path.ServiceType,
service graph.Servicer,
resourceOwner string,
) string {
var (
err error
d models.Driveable
)
switch backupService {
case path.OneDriveService:
d, err = service.Client().UsersById(resourceOwner).Drive().Get(ctx, nil)
case path.SharePointService:
d, err = service.Client().SitesById(resourceOwner).Drive().Get(ctx, nil)
default:
assert.FailNowf(t, "unknown service type %s", backupService.String())
}
if err != nil {
err = graph.Wrap(ctx, err, "retrieving drive")
}
require.NoError(t, err, clues.ToCore(err))
id := ptr.Val(d.GetId())
require.NotEmpty(t, id)
return id
}
type suiteInfo interface {
Service() graph.Servicer
Account() account.Account
Tenant() string
// Returns (username, user ID) for the user.
// Returns (username, user ID) for the user. These values are used for
// permissions.
PrimaryUser() (string, string)
SecondaryUser() (string, string)
// BackupResourceOwner returns the resource owner to run the backup/restore
// with. This can be different from the values used for permissions and it can
// also be a site.
BackupResourceOwner() string
BackupService() path.ServiceType
Resource() resource
}
type GraphConnectorOneDriveIntegrationSuite struct {
type oneDriveSuite interface {
tester.Suite
suiteInfo
}
type suiteInfoImpl struct {
connector *GraphConnector
resourceOwner string
user string
userID string
secondaryUser string
secondaryUserID string
acct account.Account
service path.ServiceType
resourceType resource
}
func (si suiteInfoImpl) Service() graph.Servicer {
return si.connector.Service
}
func (si suiteInfoImpl) Account() account.Account {
return si.acct
}
func (si suiteInfoImpl) Tenant() string {
return si.connector.tenant
}
func (si suiteInfoImpl) PrimaryUser() (string, string) {
return si.user, si.userID
}
func (si suiteInfoImpl) SecondaryUser() (string, string) {
return si.secondaryUser, si.secondaryUserID
}
func (si suiteInfoImpl) BackupResourceOwner() string {
return si.resourceOwner
}
func (si suiteInfoImpl) BackupService() path.ServiceType {
return si.service
}
func (si suiteInfoImpl) Resource() resource {
return si.resourceType
}
// ---------------------------------------------------------------------------
// SharePoint Libraries
// ---------------------------------------------------------------------------
// SharePoint shares most of its libraries implementation with OneDrive so we
// only test simple things here and leave the more extensive testing to
// OneDrive.
//
// TODO(ashmrtn): SharePoint doesn't have permissions backup/restore enabled
// right now. Adjust the tests here when that is enabled so we have at least
// basic assurances that it's doing the right thing. We can leave the more
// extensive permissions tests to OneDrive as well.
type GraphConnectorSharePointIntegrationSuite struct {
tester.Suite
suiteInfo
}
func TestGraphConnectorSharePointIntegrationSuite(t *testing.T) {
suite.Run(t, &GraphConnectorSharePointIntegrationSuite{
Suite: tester.NewIntegrationSuite(
t,
[][]string{tester.M365AcctCredEnvs},
),
})
}
func (suite *GraphConnectorSharePointIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext()
defer flush()
si := suiteInfoImpl{
connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Sites),
user: tester.M365UserID(suite.T()),
secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.SharePointService,
resourceType: Sites,
}
si.resourceOwner = tester.M365SiteID(suite.T())
user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
si.userID = ptr.Val(user.GetId())
secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
si.secondaryUserID = ptr.Val(secondaryUser.GetId())
suite.suiteInfo = si
}
func (suite *GraphConnectorSharePointIntegrationSuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(suite, version.Backup)
}
// ---------------------------------------------------------------------------
// OneDrive most recent backup version
// ---------------------------------------------------------------------------
type GraphConnectorOneDriveIntegrationSuite struct {
tester.Suite
suiteInfo
}
func TestGraphConnectorOneDriveIntegrationSuite(t *testing.T) {
@ -331,38 +488,26 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext()
defer flush()
suite.connector = loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users)
suite.user = tester.M365UserID(suite.T())
suite.secondaryUser = tester.SecondaryM365UserID(suite.T())
suite.acct = tester.NewM365Account(suite.T())
si := suiteInfoImpl{
connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users),
user: tester.M365UserID(suite.T()),
secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.OneDriveService,
resourceType: Users,
}
user, err := suite.connector.Owners.Users().GetByID(ctx, suite.user)
require.NoError(suite.T(), err, "fetching user", suite.user, clues.ToCore(err))
suite.userID = ptr.Val(user.GetId())
si.resourceOwner = si.user
secondaryUser, err := suite.connector.Owners.Users().GetByID(ctx, suite.secondaryUser)
require.NoError(suite.T(), err, "fetching user", suite.secondaryUser, clues.ToCore(err))
suite.secondaryUserID = ptr.Val(secondaryUser.GetId())
}
user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
si.userID = ptr.Val(user.GetId())
func (suite *GraphConnectorOneDriveIntegrationSuite) Service() graph.Servicer {
return suite.connector.Service
}
secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
si.secondaryUserID = ptr.Val(secondaryUser.GetId())
func (suite *GraphConnectorOneDriveIntegrationSuite) Account() account.Account {
return suite.acct
}
func (suite *GraphConnectorOneDriveIntegrationSuite) Tenant() string {
return suite.connector.tenant
}
func (suite *GraphConnectorOneDriveIntegrationSuite) PrimaryUser() (string, string) {
return suite.user, suite.userID
}
func (suite *GraphConnectorOneDriveIntegrationSuite) SecondaryUser() (string, string) {
return suite.secondaryUser, suite.secondaryUserID
suite.suiteInfo = si
}
func (suite *GraphConnectorOneDriveIntegrationSuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
@ -391,14 +536,14 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
t := suite.T()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser()
driveID := mustGetDefaultDriveID(
t,
ctx,
suite.BackupService(),
suite.Service(),
userName,
suite.BackupResourceOwner(),
)
secondaryUserRead := permData{
@ -414,12 +559,13 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
}
test := restoreBackupInfoMultiVersion{
service: path.OneDriveService,
resource: Users,
service: suite.BackupService(),
resource: suite.Resource(),
backupVersion: version.Backup,
collectionsPrevious: []colInfo{
newOneDriveCollection(
suite.T(),
suite.BackupService(),
[]string{
"drives",
driveID,
@ -439,6 +585,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collection(),
newOneDriveCollection(
suite.T(),
suite.BackupService(),
[]string{
"drives",
driveID,
@ -460,6 +607,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collectionsLatest: []colInfo{
newOneDriveCollection(
suite.T(),
suite.BackupService(),
[]string{
"drives",
driveID,
@ -479,6 +627,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collection(),
newOneDriveCollection(
suite.T(),
suite.BackupService(),
[]string{
"drives",
driveID,
@ -506,7 +655,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
suite.Account(),
test,
suite.Tenant(),
[]string{userName},
[]string{suite.BackupResourceOwner()},
control.Options{
RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: false},
@ -514,14 +663,12 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
)
}
// ---------------------------------------------------------------------------
// OneDrive regression
// ---------------------------------------------------------------------------
type GraphConnectorOneDriveNightlySuite struct {
tester.Suite
connector *GraphConnector
user string
userID string
secondaryUser string
secondaryUserID string
acct account.Account
suiteInfo
}
func TestGraphConnectorOneDriveNightlySuite(t *testing.T) {
@ -537,38 +684,26 @@ func (suite *GraphConnectorOneDriveNightlySuite) SetupSuite() {
ctx, flush := tester.NewContext()
defer flush()
suite.connector = loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users)
suite.user = tester.M365UserID(suite.T())
suite.secondaryUser = tester.SecondaryM365UserID(suite.T())
suite.acct = tester.NewM365Account(suite.T())
si := suiteInfoImpl{
connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users),
user: tester.M365UserID(suite.T()),
secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.OneDriveService,
resourceType: Users,
}
user, err := suite.connector.Owners.Users().GetByID(ctx, suite.user)
require.NoError(suite.T(), err, "fetching user", suite.user, clues.ToCore(err))
suite.userID = ptr.Val(user.GetId())
si.resourceOwner = si.user
secondaryUser, err := suite.connector.Owners.Users().GetByID(ctx, suite.secondaryUser)
require.NoError(suite.T(), err, "fetching user", suite.secondaryUser, clues.ToCore(err))
suite.secondaryUserID = ptr.Val(secondaryUser.GetId())
}
user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
si.userID = ptr.Val(user.GetId())
func (suite *GraphConnectorOneDriveNightlySuite) Service() graph.Servicer {
return suite.connector.Service
}
secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
si.secondaryUserID = ptr.Val(secondaryUser.GetId())
func (suite *GraphConnectorOneDriveNightlySuite) Account() account.Account {
return suite.acct
}
func (suite *GraphConnectorOneDriveNightlySuite) Tenant() string {
return suite.connector.tenant
}
func (suite *GraphConnectorOneDriveNightlySuite) PrimaryUser() (string, string) {
return suite.user, suite.userID
}
func (suite *GraphConnectorOneDriveNightlySuite) SecondaryUser() (string, string) {
return suite.secondaryUser, suite.secondaryUserID
suite.suiteInfo = si
}
func (suite *GraphConnectorOneDriveNightlySuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
@ -596,14 +731,13 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
ctx, flush := tester.NewContext()
defer flush()
userName, _ := suite.PrimaryUser()
// Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID(
suite.T(),
ctx,
suite.BackupService(),
suite.Service(),
userName,
suite.BackupResourceOwner(),
)
rootPath := []string{
@ -705,16 +839,16 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
},
}
expected := testDataForInfo(suite.T(), cols, version.Backup)
expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() {
t := suite.T()
input := testDataForInfo(t, cols, vn)
input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService,
resource: Users,
service: suite.BackupService(),
resource: suite.Resource(),
backupVersion: vn,
collectionsPrevious: input,
collectionsLatest: expected,
@ -725,7 +859,7 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
suite.Account(),
testData,
suite.Tenant(),
[]string{userName},
[]string{suite.BackupResourceOwner()},
control.Options{
RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -739,15 +873,15 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
ctx, flush := tester.NewContext()
defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID(
suite.T(),
ctx,
suite.BackupService(),
suite.Service(),
userName,
suite.BackupResourceOwner(),
)
fileName2 := "test-file2.txt"
@ -913,7 +1047,7 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
},
}
expected := testDataForInfo(suite.T(), cols, version.Backup)
expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() {
@ -921,11 +1055,11 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
// Ideally this can always be true or false and still
// work, but limiting older versions to use emails so as
// to validate that flow as well.
input := testDataForInfo(t, cols, vn)
input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService,
resource: Users,
service: suite.BackupService(),
resource: suite.Resource(),
backupVersion: vn,
collectionsPrevious: input,
collectionsLatest: expected,
@ -936,7 +1070,7 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
suite.Account(),
testData,
suite.Tenant(),
[]string{userName},
[]string{suite.BackupResourceOwner()},
control.Options{
RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -950,15 +1084,15 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
ctx, flush := tester.NewContext()
defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID(
suite.T(),
ctx,
suite.BackupService(),
suite.Service(),
userName,
suite.BackupResourceOwner(),
)
inputCols := []onedriveColInfo{
@ -999,16 +1133,16 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
},
}
expected := testDataForInfo(suite.T(), expectedCols, version.Backup)
expected := testDataForInfo(suite.T(), suite.BackupService(), expectedCols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() {
t := suite.T()
input := testDataForInfo(t, inputCols, vn)
input := testDataForInfo(t, suite.BackupService(), inputCols, vn)
testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService,
resource: Users,
service: suite.BackupService(),
resource: suite.Resource(),
backupVersion: vn,
collectionsPrevious: input,
collectionsLatest: expected,
@ -1019,7 +1153,7 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
suite.Account(),
testData,
suite.Tenant(),
[]string{userName},
[]string{suite.BackupResourceOwner()},
control.Options{
RestorePermissions: false,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -1035,15 +1169,15 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
ctx, flush := tester.NewContext()
defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID(
suite.T(),
ctx,
suite.BackupService(),
suite.Service(),
userName,
suite.BackupResourceOwner(),
)
folderAName := "custom"
@ -1148,7 +1282,7 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
},
}
expected := testDataForInfo(suite.T(), cols, version.Backup)
expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() {
@ -1156,11 +1290,11 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
// Ideally this can always be true or false and still
// work, but limiting older versions to use emails so as
// to validate that flow as well.
input := testDataForInfo(t, cols, vn)
input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService,
resource: Users,
service: suite.BackupService(),
resource: suite.Resource(),
backupVersion: vn,
collectionsPrevious: input,
collectionsLatest: expected,
@ -1171,7 +1305,7 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
suite.Account(),
testData,
suite.Tenant(),
[]string{userName},
[]string{suite.BackupResourceOwner()},
control.Options{
RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},

View File

@ -11,7 +11,6 @@ import (
"golang.org/x/exp/maps"
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/mockconnector"
"github.com/alcionai/corso/src/internal/data"
@ -314,27 +313,6 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
// Exchange Functions
//-------------------------------------------------------------
//revive:disable:context-as-argument
func mustGetDefaultDriveID(
t *testing.T,
ctx context.Context,
service graph.Servicer,
userID string,
) string {
//revive:enable:context-as-argument
d, err := service.Client().UsersById(userID).Drive().Get(ctx, nil)
if err != nil {
err = graph.Wrap(ctx, err, "retrieving drive")
}
require.NoError(t, err, clues.ToCore(err))
id := ptr.Val(d.GetId())
require.NotEmpty(t, id)
return id
}
func getCollectionsAndExpected(
t *testing.T,
config configInfo,
@ -971,8 +949,8 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames
// Always just 1 because it's just 1 collection.
assert.Equal(t, totalItems, status.Metrics.Objects, "status.Metrics.Objects")
assert.Equal(t, totalItems, status.Metrics.Successes, "status.Metrics.Successes")
assert.Equal(
t, totalItems, len(deets.Entries),
assert.Len(
t, deets.Entries, totalItems,
"details entries contains same item count as total successful items restored")
t.Log("Restore complete")