remove redundant type check (#4199)

info.itemType already looks through each service entry to find the item type.  A service nil check is redundant. Adds a qol func for asking if an itemInfo is a driveish item.

---

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🐛 Bugfix

#### Issue(s)

* #3990 

#### Test Plan

- [x] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-09-07 12:30:46 -06:00 committed by GitHub
parent 2e6a47e92f
commit c74585eafc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 175 additions and 150 deletions

View File

@ -17,7 +17,6 @@ import (
"github.com/alcionai/corso/src/internal/common/str" "github.com/alcionai/corso/src/internal/common/str"
"github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
odStub "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub" odStub "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub"
m365Stub "github.com/alcionai/corso/src/internal/m365/stub" m365Stub "github.com/alcionai/corso/src/internal/m365/stub"
@ -121,7 +120,6 @@ func generateAndRestoreItems(
func getControllerAndVerifyResourceOwner( func getControllerAndVerifyResourceOwner(
ctx context.Context, ctx context.Context,
resourceCat resource.Category,
resourceOwner string, resourceOwner string,
pst path.ServiceType, pst path.ServiceType,
) ( ) (
@ -147,7 +145,7 @@ func getControllerAndVerifyResourceOwner(
return nil, account.Account{}, nil, clues.Wrap(err, "finding m365 account details") return nil, account.Account{}, nil, clues.Wrap(err, "finding m365 account details")
} }
ctrl, err := m365.NewController(ctx, acct, resourceCat, pst, control.Options{}) ctrl, err := m365.NewController(ctx, acct, pst, control.Options{})
if err != nil { if err != nil {
return nil, account.Account{}, nil, clues.Wrap(err, "connecting to graph api") return nil, account.Account{}, nil, clues.Wrap(err, "connecting to graph api")
} }
@ -430,7 +428,6 @@ func generateAndRestoreDriveItems(
config := m365Stub.ConfigInfo{ config := m365Stub.ConfigInfo{
Opts: opts, Opts: opts,
Resource: resource.Users,
Service: service, Service: service,
Tenant: tenantID, Tenant: tenantID,
ResourceOwners: []string{protectedResource.ID()}, ResourceOwners: []string{protectedResource.ID()},

View File

@ -5,7 +5,6 @@ import (
. "github.com/alcionai/corso/src/cli/print" . "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/count" "github.com/alcionai/corso/src/pkg/count"
@ -53,7 +52,7 @@ func handleExchangeEmailFactory(cmd *cobra.Command, args []string) error {
return nil return nil
} }
ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, resource.Users, User, path.ExchangeService) ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, User, path.ExchangeService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -100,7 +99,7 @@ func handleExchangeCalendarEventFactory(cmd *cobra.Command, args []string) error
return nil return nil
} }
ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, resource.Users, User, path.ExchangeService) ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, User, path.ExchangeService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }
@ -149,7 +148,7 @@ func handleExchangeContactFactory(cmd *cobra.Command, args []string) error {
return nil return nil
} }
ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, resource.Users, User, path.ExchangeService) ctrl, _, _, err := getControllerAndVerifyResourceOwner(ctx, User, path.ExchangeService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -7,7 +7,6 @@ import (
. "github.com/alcionai/corso/src/cli/print" . "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/pkg/count" "github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/logger"
@ -37,7 +36,7 @@ func handleOneDriveFileFactory(cmd *cobra.Command, args []string) error {
return nil return nil
} }
ctrl, acct, inp, err := getControllerAndVerifyResourceOwner(ctx, resource.Users, User, path.OneDriveService) ctrl, acct, inp, err := getControllerAndVerifyResourceOwner(ctx, User, path.OneDriveService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -7,7 +7,6 @@ import (
. "github.com/alcionai/corso/src/cli/print" . "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/pkg/count" "github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/logger"
@ -37,7 +36,7 @@ func handleSharePointLibraryFileFactory(cmd *cobra.Command, args []string) error
return nil return nil
} }
ctrl, acct, inp, err := getControllerAndVerifyResourceOwner(ctx, resource.Sites, Site, path.SharePointService) ctrl, acct, inp, err := getControllerAndVerifyResourceOwner(ctx, Site, path.SharePointService)
if err != nil { if err != nil {
return Only(ctx, err) return Only(ctx, err)
} }

View File

@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
inMock "github.com/alcionai/corso/src/internal/common/idname/mock" inMock "github.com/alcionai/corso/src/internal/common/idname/mock"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/internal/m365/service/exchange" "github.com/alcionai/corso/src/internal/m365/service/exchange"
odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts" odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts"
"github.com/alcionai/corso/src/internal/m365/service/sharepoint" "github.com/alcionai/corso/src/internal/m365/service/sharepoint"
@ -69,7 +68,7 @@ func (suite *DataCollectionIntgSuite) TestExchangeDataCollection() {
selUsers := []string{suite.user} selUsers := []string{suite.user}
ctrl := newController(ctx, suite.T(), resource.Users, path.ExchangeService) ctrl := newController(ctx, suite.T(), path.ExchangeService)
tests := []struct { tests := []struct {
name string name string
getSelector func(t *testing.T) selectors.Selector getSelector func(t *testing.T) selectors.Selector
@ -175,7 +174,7 @@ func (suite *DataCollectionIntgSuite) TestDataCollections_invalidResourceOwner()
defer flush() defer flush()
owners := []string{"snuffleupagus"} owners := []string{"snuffleupagus"}
ctrl := newController(ctx, suite.T(), resource.Users, path.ExchangeService) ctrl := newController(ctx, suite.T(), path.ExchangeService)
tests := []struct { tests := []struct {
name string name string
getSelector func(t *testing.T) selectors.Selector getSelector func(t *testing.T) selectors.Selector
@ -263,7 +262,7 @@ func (suite *DataCollectionIntgSuite) TestSharePointDataCollection() {
defer flush() defer flush()
selSites := []string{suite.site} selSites := []string{suite.site}
ctrl := newController(ctx, suite.T(), resource.Sites, path.SharePointService) ctrl := newController(ctx, suite.T(), path.SharePointService)
tests := []struct { tests := []struct {
name string name string
expected int expected int
@ -361,7 +360,7 @@ func (suite *SPCollectionIntgSuite) SetupSuite() {
ctx, flush := tester.NewContext(suite.T()) ctx, flush := tester.NewContext(suite.T())
defer flush() defer flush()
suite.connector = newController(ctx, suite.T(), resource.Sites, path.SharePointService) suite.connector = newController(ctx, suite.T(), path.SharePointService)
suite.user = tconfig.M365UserID(suite.T()) suite.user = tconfig.M365UserID(suite.T())
tester.LogTimeOfTest(suite.T()) tester.LogTimeOfTest(suite.T())
@ -375,7 +374,7 @@ func (suite *SPCollectionIntgSuite) TestCreateSharePointCollection_Libraries() {
var ( var (
siteID = tconfig.M365SiteID(t) siteID = tconfig.M365SiteID(t)
ctrl = newController(ctx, t, resource.Sites, path.SharePointService) ctrl = newController(ctx, t, path.SharePointService)
siteIDs = []string{siteID} siteIDs = []string{siteID}
) )
@ -425,7 +424,7 @@ func (suite *SPCollectionIntgSuite) TestCreateSharePointCollection_Lists() {
var ( var (
siteID = tconfig.M365SiteID(t) siteID = tconfig.M365SiteID(t)
ctrl = newController(ctx, t, resource.Sites, path.SharePointService) ctrl = newController(ctx, t, path.SharePointService)
siteIDs = []string{siteID} siteIDs = []string{siteID}
) )
@ -492,7 +491,7 @@ func (suite *GroupsCollectionIntgSuite) SetupSuite() {
ctx, flush := tester.NewContext(t) ctx, flush := tester.NewContext(t)
defer flush() defer flush()
suite.connector = newController(ctx, t, resource.Sites, path.GroupsService) suite.connector = newController(ctx, t, path.GroupsService)
suite.user = tconfig.M365UserID(t) suite.user = tconfig.M365UserID(t)
acct := tconfig.NewM365Account(t) acct := tconfig.NewM365Account(t)
@ -512,7 +511,7 @@ func (suite *GroupsCollectionIntgSuite) TestCreateGroupsCollection_SharePoint()
var ( var (
groupID = tconfig.M365GroupID(t) groupID = tconfig.M365GroupID(t)
ctrl = newController(ctx, t, resource.Groups, path.GroupsService) ctrl = newController(ctx, t, path.GroupsService)
groupIDs = []string{groupID} groupIDs = []string{groupID}
) )

View File

@ -59,7 +59,6 @@ type Controller struct {
func NewController( func NewController(
ctx context.Context, ctx context.Context,
acct account.Account, acct account.Account,
rc resource.Category,
pst path.ServiceType, pst path.ServiceType,
co control.Options, co control.Options,
) (*Controller, error) { ) (*Controller, error) {
@ -75,6 +74,17 @@ func NewController(
return nil, clues.Wrap(err, "creating api client").WithClues(ctx) return nil, clues.Wrap(err, "creating api client").WithClues(ctx)
} }
rc := resource.UnknownResource
switch pst {
case path.ExchangeService, path.OneDriveService:
rc = resource.Users
case path.GroupsService:
rc = resource.Groups
case path.SharePointService:
rc = resource.Sites
}
rCli, err := getResourceClient(rc, ac) rCli, err := getResourceClient(rc, ac)
if err != nil { if err != nil {
return nil, clues.Wrap(err, "creating resource client").WithClues(ctx) return nil, clues.Wrap(err, "creating resource client").WithClues(ctx)

View File

@ -366,7 +366,7 @@ func (suite *ControllerIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext(t) ctx, flush := tester.NewContext(t)
defer flush() defer flush()
suite.ctrl = newController(ctx, t, resource.Users, path.ExchangeService) suite.ctrl = newController(ctx, t, path.ExchangeService)
suite.user = tconfig.M365UserID(t) suite.user = tconfig.M365UserID(t)
suite.secondaryUser = tconfig.SecondaryM365UserID(t) suite.secondaryUser = tconfig.SecondaryM365UserID(t)
@ -472,7 +472,7 @@ func runRestore(
start := time.Now() start := time.Now()
restoreCtrl := newController(ctx, t, sci.Resource, path.ExchangeService) restoreCtrl := newController(ctx, t, path.ExchangeService)
restoreSel := getSelectorWith(t, sci.Service, sci.ResourceOwners, true) restoreSel := getSelectorWith(t, sci.Service, sci.ResourceOwners, true)
rcc := inject.RestoreConsumerConfig{ rcc := inject.RestoreConsumerConfig{
@ -541,7 +541,7 @@ func runBackupAndCompare(
nameToID[ro] = ro nameToID[ro] = ro
} }
backupCtrl := newController(ctx, t, sci.Resource, path.ExchangeService) backupCtrl := newController(ctx, t, path.ExchangeService)
backupCtrl.IDNameLookup = inMock.NewCache(idToName, nameToID) backupCtrl.IDNameLookup = inMock.NewCache(idToName, nameToID)
backupSel := backupSelectorForExpected(t, sci.Service, expectedDests) backupSel := backupSelectorForExpected(t, sci.Service, expectedDests)
@ -597,7 +597,6 @@ func runRestoreBackupTest(
cfg := stub.ConfigInfo{ cfg := stub.ConfigInfo{
Opts: opts, Opts: opts,
Resource: test.resourceCat,
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
@ -643,7 +642,6 @@ func runRestoreTestWithVersion(
cfg := stub.ConfigInfo{ cfg := stub.ConfigInfo{
Opts: opts, Opts: opts,
Resource: test.resourceCat,
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
@ -681,7 +679,6 @@ func runRestoreBackupTestVersions(
cfg := stub.ConfigInfo{ cfg := stub.ConfigInfo{
Opts: opts, Opts: opts,
Resource: test.resourceCat,
Service: test.service, Service: test.service,
Tenant: tenant, Tenant: tenant,
ResourceOwners: resourceOwners, ResourceOwners: resourceOwners,
@ -725,9 +722,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_core() {
table := []restoreBackupInfo{ table := []restoreBackupInfo{
{ {
name: "EmailsWithAttachments", name: "EmailsWithAttachments",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{api.MailInbox}, PathElements: []string{api.MailInbox},
@ -752,9 +748,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_core() {
}, },
}, },
{ {
name: "MultipleEmailsMultipleFolders", name: "MultipleEmailsMultipleFolders",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{api.MailInbox}, PathElements: []string{api.MailInbox},
@ -828,9 +823,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_core() {
}, },
}, },
{ {
name: "MultipleContactsSingleFolder", name: "MultipleContactsSingleFolder",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{"Contacts"}, PathElements: []string{"Contacts"},
@ -856,9 +850,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_core() {
}, },
}, },
{ {
name: "MultipleContactsMultipleFolders", name: "MultipleContactsMultipleFolders",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{"Work"}, PathElements: []string{"Work"},
@ -987,9 +980,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_core() {
func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() { func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() {
table := []restoreBackupInfo{ table := []restoreBackupInfo{
{ {
name: "Contacts", name: "Contacts",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{"Work"}, PathElements: []string{"Work"},
@ -1093,7 +1085,7 @@ func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() {
restoreCfg.Location, restoreCfg.Location,
) )
restoreCtrl := newController(ctx, t, test.resourceCat, path.ExchangeService) restoreCtrl := newController(ctx, t, path.ExchangeService)
rcc := inject.RestoreConsumerConfig{ rcc := inject.RestoreConsumerConfig{
BackupVersion: version.Backup, BackupVersion: version.Backup,
@ -1127,7 +1119,7 @@ func (suite *ControllerIntegrationSuite) TestMultiFolderBackupDifferentNames() {
// Run a backup and compare its output with what we put in. // Run a backup and compare its output with what we put in.
backupCtrl := newController(ctx, t, test.resourceCat, path.ExchangeService) backupCtrl := newController(ctx, t, path.ExchangeService)
backupSel := backupSelectorForExpected(t, test.service, expectedDests) backupSel := backupSelectorForExpected(t, test.service, expectedDests)
t.Log("Selective backup of", backupSel) t.Log("Selective backup of", backupSel)
@ -1175,9 +1167,8 @@ func (suite *ControllerIntegrationSuite) TestRestoreAndBackup_largeMailAttachmen
subjectText := "Test message for restore with large attachment" subjectText := "Test message for restore with large attachment"
test := restoreBackupInfo{ test := restoreBackupInfo{
name: "EmailsWithLargeAttachments", name: "EmailsWithLargeAttachments",
service: path.ExchangeService, service: path.ExchangeService,
resourceCat: resource.Users,
collections: []stub.ColInfo{ collections: []stub.ColInfo{
{ {
PathElements: []string{api.MailInbox}, PathElements: []string{api.MailInbox},
@ -1278,7 +1269,7 @@ func (suite *ControllerIntegrationSuite) TestBackup_CreatesPrefixCollections() {
defer flush() defer flush()
var ( var (
backupCtrl = newController(ctx, t, test.resourceCat, path.ExchangeService) backupCtrl = newController(ctx, t, test.service)
backupSel = test.selectorFunc(t) backupSel = test.selectorFunc(t)
errs = fault.New(true) errs = fault.New(true)
start = time.Now() start = time.Now()

View File

@ -19,7 +19,6 @@ import (
"github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/m365/collection/drive" "github.com/alcionai/corso/src/internal/m365/collection/drive"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
"github.com/alcionai/corso/src/internal/m365/resource"
odStub "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub" odStub "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub"
m365Stub "github.com/alcionai/corso/src/internal/m365/stub" m365Stub "github.com/alcionai/corso/src/internal/m365/stub"
"github.com/alcionai/corso/src/internal/tester/tconfig" "github.com/alcionai/corso/src/internal/tester/tconfig"
@ -106,14 +105,12 @@ type restoreBackupInfo struct {
name string name string
service path.ServiceType service path.ServiceType
collections []m365Stub.ColInfo collections []m365Stub.ColInfo
resourceCat resource.Category
} }
type restoreBackupInfoMultiVersion struct { type restoreBackupInfoMultiVersion struct {
service path.ServiceType service path.ServiceType
collectionsLatest []m365Stub.ColInfo collectionsLatest []m365Stub.ColInfo
collectionsPrevious []m365Stub.ColInfo collectionsPrevious []m365Stub.ColInfo
resourceCat resource.Category
backupVersion int backupVersion int
} }
@ -1197,12 +1194,11 @@ func getSelectorWith(
func newController( func newController(
ctx context.Context, ctx context.Context,
t *testing.T, t *testing.T,
r resource.Category,
pst path.ServiceType, pst path.ServiceType,
) *Controller { ) *Controller {
a := tconfig.NewM365Account(t) a := tconfig.NewM365Account(t)
controller, err := NewController(ctx, a, r, pst, control.Options{}) controller, err := NewController(ctx, a, pst, control.Options{})
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
return controller return controller

View File

@ -16,7 +16,6 @@ import (
"github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/resource"
odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts" odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts"
"github.com/alcionai/corso/src/internal/m365/service/onedrive/stub" "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
@ -91,7 +90,6 @@ type suiteInfo interface {
// also be a site. // also be a site.
ResourceOwner() string ResourceOwner() string
Service() path.ServiceType Service() path.ServiceType
Resource() resource.Category
} }
type oneDriveSuite interface { type oneDriveSuite interface {
@ -100,17 +98,16 @@ type oneDriveSuite interface {
} }
type suiteInfoImpl struct { type suiteInfoImpl struct {
ac api.Client ac api.Client
controller *Controller controller *Controller
resourceOwner string resourceOwner string
resourceCategory resource.Category secondaryUser string
secondaryUser string secondaryUserID string
secondaryUserID string service path.ServiceType
service path.ServiceType tertiaryUser string
tertiaryUser string tertiaryUserID string
tertiaryUserID string user string
user string userID string
userID string
} }
func NewSuiteInfoImpl( func NewSuiteInfoImpl(
@ -119,22 +116,16 @@ func NewSuiteInfoImpl(
resourceOwner string, resourceOwner string,
service path.ServiceType, service path.ServiceType,
) suiteInfoImpl { ) suiteInfoImpl {
rsc := resource.Users ctrl := newController(ctx, t, path.OneDriveService)
if service == path.SharePointService {
rsc = resource.Sites
}
ctrl := newController(ctx, t, rsc, path.OneDriveService)
return suiteInfoImpl{ return suiteInfoImpl{
ac: ctrl.AC, ac: ctrl.AC,
controller: ctrl, controller: ctrl,
resourceOwner: resourceOwner, resourceOwner: resourceOwner,
resourceCategory: rsc, secondaryUser: tconfig.SecondaryM365UserID(t),
secondaryUser: tconfig.SecondaryM365UserID(t), service: service,
service: service, tertiaryUser: tconfig.TertiaryM365UserID(t),
tertiaryUser: tconfig.TertiaryM365UserID(t), user: tconfig.M365UserID(t),
user: tconfig.M365UserID(t),
} }
} }
@ -166,10 +157,6 @@ func (si suiteInfoImpl) Service() path.ServiceType {
return si.service return si.service
} }
func (si suiteInfoImpl) Resource() resource.Category {
return si.resourceCategory
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// SharePoint Libraries // SharePoint Libraries
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -512,7 +499,6 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -761,7 +747,6 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -851,7 +836,6 @@ func testRestoreNoPermissionsAndBackup(suite oneDriveSuite, startVersion int) {
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -1056,7 +1040,6 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -1251,7 +1234,6 @@ func testLinkSharesInheritanceRestoreAndBackup(suite oneDriveSuite, startVersion
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -1368,7 +1350,6 @@ func testRestoreFolderNamedFolderRegression(
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: suite.Service(), service: suite.Service(),
resourceCat: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,

View File

@ -10,7 +10,6 @@ import (
dataMock "github.com/alcionai/corso/src/internal/data/mock" dataMock "github.com/alcionai/corso/src/internal/data/mock"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
"github.com/alcionai/corso/src/internal/m365/mock" "github.com/alcionai/corso/src/internal/m365/mock"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
@ -43,7 +42,6 @@ type ItemInfo struct {
type ConfigInfo struct { type ConfigInfo struct {
Opts control.Options Opts control.Options
Resource resource.Category
Service path.ServiceType Service path.ServiceType
Tenant string Tenant string
ResourceOwners []string ResourceOwners []string

View File

@ -9,7 +9,6 @@ import (
"github.com/alcionai/corso/src/internal/common/idname" "github.com/alcionai/corso/src/internal/common/idname"
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/pkg/account" "github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
@ -22,12 +21,11 @@ func ControllerWithSelector(
t *testing.T, t *testing.T,
ctx context.Context, //revive:disable-line:context-as-argument ctx context.Context, //revive:disable-line:context-as-argument
acct account.Account, acct account.Account,
cr resource.Category,
sel selectors.Selector, sel selectors.Selector,
ins idname.Cacher, ins idname.Cacher,
onFail func(), onFail func(),
) (*m365.Controller, selectors.Selector) { ) (*m365.Controller, selectors.Selector) {
ctrl, err := m365.NewController(ctx, acct, cr, sel.PathService(), control.DefaultOptions()) ctrl, err := m365.NewController(ctx, acct, sel.PathService(), control.DefaultOptions())
if !assert.NoError(t, err, clues.ToCore(err)) { if !assert.NoError(t, err, clues.ToCore(err)) {
if onFail != nil { if onFail != nil {
onFail() onFail()

View File

@ -19,7 +19,6 @@ import (
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/mock" "github.com/alcionai/corso/src/internal/m365/mock"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
"github.com/alcionai/corso/src/internal/operations/inject" "github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/internal/stats" "github.com/alcionai/corso/src/internal/stats"
@ -344,7 +343,6 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run_errorNoBackup() {
ctrl, err := m365.NewController( ctrl, err := m365.NewController(
ctx, ctx,
suite.acct, suite.acct,
resource.Users,
rsel.PathService(), rsel.PathService(),
control.DefaultOptions()) control.DefaultOptions())
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))

View File

@ -20,7 +20,6 @@ import (
evmock "github.com/alcionai/corso/src/internal/events/mock" evmock "github.com/alcionai/corso/src/internal/events/mock"
"github.com/alcionai/corso/src/internal/m365/collection/exchange" "github.com/alcionai/corso/src/internal/m365/collection/exchange"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
exchTD "github.com/alcionai/corso/src/internal/m365/service/exchange/testdata" exchTD "github.com/alcionai/corso/src/internal/m365/service/exchange/testdata"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
@ -264,7 +263,7 @@ func testExchangeContinuousBackups(suite *ExchangeBackupIntgSuite, toggles contr
) )
opts.ToggleFeatures = toggles opts.ToggleFeatures = toggles
ctrl, sels := ControllerWithSelector(t, ctx, acct, resource.Users, sel.Selector, nil, nil) ctrl, sels := ControllerWithSelector(t, ctx, acct, sel.Selector, nil, nil)
sel.DiscreteOwner = sels.ID() sel.DiscreteOwner = sels.ID()
sel.DiscreteOwnerName = sels.Name() sel.DiscreteOwnerName = sels.Name()

View File

@ -20,7 +20,6 @@ import (
"github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/kopia"
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/resource"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock" exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts" odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts"
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
@ -132,22 +131,12 @@ func prepNewTestBackupOp(
bod.sw = store.NewWrapper(bod.kms) bod.sw = store.NewWrapper(bod.kms)
var connectorResource resource.Category
switch sel.PathService() {
case path.SharePointService:
connectorResource = resource.Sites
case path.GroupsService:
connectorResource = resource.Groups
default:
connectorResource = resource.Users
}
bod.ctrl, bod.sel = ControllerWithSelector( bod.ctrl, bod.sel = ControllerWithSelector(
t, t,
ctx, ctx,
bod.acct, bod.acct,
connectorResource, sel, nil, sel,
nil,
bod.close) bod.close)
bo := newTestBackupOp( bo := newTestBackupOp(
@ -543,12 +532,11 @@ func ControllerWithSelector(
t *testing.T, t *testing.T,
ctx context.Context, //revive:disable-line:context-as-argument ctx context.Context, //revive:disable-line:context-as-argument
acct account.Account, acct account.Account,
rc resource.Category,
sel selectors.Selector, sel selectors.Selector,
ins idname.Cacher, ins idname.Cacher,
onFail func(*testing.T, context.Context), onFail func(*testing.T, context.Context),
) (*m365.Controller, selectors.Selector) { ) (*m365.Controller, selectors.Selector) {
ctrl, err := m365.NewController(ctx, acct, rc, sel.PathService(), control.DefaultOptions()) ctrl, err := m365.NewController(ctx, acct, sel.PathService(), control.DefaultOptions())
if !assert.NoError(t, err, clues.ToCore(err)) { if !assert.NoError(t, err, clues.ToCore(err)) {
if onFail != nil { if onFail != nil {
onFail(t, ctx) onFail(t, ctx)

View File

@ -23,7 +23,6 @@ import (
"github.com/alcionai/corso/src/internal/m365/collection/drive" "github.com/alcionai/corso/src/internal/m365/collection/drive"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/internal/streamstore" "github.com/alcionai/corso/src/internal/streamstore"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
@ -140,7 +139,6 @@ func (suite *OneDriveBackupIntgSuite) TestBackup_Run_incrementalOneDrive() {
suite, suite,
suite.its.user.ID, suite.its.user.ID,
suite.its.user.ID, suite.its.user.ID,
resource.Users,
path.OneDriveService, path.OneDriveService,
path.FilesCategory, path.FilesCategory,
ic, ic,
@ -152,7 +150,6 @@ func (suite *OneDriveBackupIntgSuite) TestBackup_Run_incrementalOneDrive() {
func runDriveIncrementalTest( func runDriveIncrementalTest(
suite tester.Suite, suite tester.Suite,
owner, permissionsUser string, owner, permissionsUser string,
rc resource.Category,
service path.ServiceType, service path.ServiceType,
category path.CategoryType, category path.CategoryType,
includeContainers func([]string) selectors.Selector, includeContainers func([]string) selectors.Selector,
@ -195,7 +192,7 @@ func runDriveIncrementalTest(
creds, err := acct.M365Config() creds, err := acct.M365Config()
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
ctrl, sel := ControllerWithSelector(t, ctx, acct, rc, sel, nil, nil) ctrl, sel := ControllerWithSelector(t, ctx, acct, sel, nil, nil)
ac := ctrl.AC.Drives() ac := ctrl.AC.Drives()
rh := getRestoreHandler(ctrl.AC) rh := getRestoreHandler(ctrl.AC)
@ -684,7 +681,7 @@ func runDriveIncrementalTest(
} }
for _, test := range table { for _, test := range table {
suite.Run(test.name, func() { suite.Run(test.name, func() {
cleanCtrl, err := m365.NewController(ctx, acct, rc, sel.PathService(), control.DefaultOptions()) cleanCtrl, err := m365.NewController(ctx, acct, sel.PathService(), control.DefaultOptions())
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
bod.ctrl = cleanCtrl bod.ctrl = cleanCtrl
@ -800,7 +797,6 @@ func (suite *OneDriveBackupIntgSuite) TestBackup_Run_oneDriveOwnerMigration() {
ctrl, err := m365.NewController( ctrl, err := m365.NewController(
ctx, ctx,
acct, acct,
resource.Users,
path.OneDriveService, path.OneDriveService,
control.DefaultOptions()) control.DefaultOptions())
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))

View File

@ -13,7 +13,6 @@ import (
evmock "github.com/alcionai/corso/src/internal/events/mock" evmock "github.com/alcionai/corso/src/internal/events/mock"
"github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/kopia"
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/internal/operations" "github.com/alcionai/corso/src/internal/operations"
"github.com/alcionai/corso/src/internal/streamstore" "github.com/alcionai/corso/src/internal/streamstore"
@ -107,20 +106,10 @@ func prepNewTestRestoreOp(
rod.sw = store.NewWrapper(rod.kms) rod.sw = store.NewWrapper(rod.kms)
connectorResource := resource.Users
switch sel.Service {
case selectors.ServiceSharePoint:
connectorResource = resource.Sites
case selectors.ServiceGroups:
connectorResource = resource.Groups
}
rod.ctrl, rod.sel = ControllerWithSelector( rod.ctrl, rod.sel = ControllerWithSelector(
t, t,
ctx, ctx,
rod.acct, rod.acct,
connectorResource,
sel, sel,
nil, nil,
rod.close) rod.close)

View File

@ -15,7 +15,6 @@ import (
evmock "github.com/alcionai/corso/src/internal/events/mock" evmock "github.com/alcionai/corso/src/internal/events/mock"
"github.com/alcionai/corso/src/internal/m365/collection/drive" "github.com/alcionai/corso/src/internal/m365/collection/drive"
"github.com/alcionai/corso/src/internal/m365/graph" "github.com/alcionai/corso/src/internal/m365/graph"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/tester/tconfig" "github.com/alcionai/corso/src/internal/tester/tconfig"
"github.com/alcionai/corso/src/internal/version" "github.com/alcionai/corso/src/internal/version"
@ -81,7 +80,6 @@ func (suite *SharePointBackupIntgSuite) TestBackup_Run_incrementalSharePoint() {
suite, suite,
suite.its.site.ID, suite.its.site.ID,
suite.its.user.ID, suite.its.user.ID,
resource.Sites,
path.SharePointService, path.SharePointService,
path.LibrariesCategory, path.LibrariesCategory,
ic, ic,

View File

@ -46,11 +46,7 @@ func (d *Details) add(
// Use the item name and the path for the ShortRef. This ensures that renames // Use the item name and the path for the ShortRef. This ensures that renames
// within a directory generate unique ShortRefs. // within a directory generate unique ShortRefs.
if info.infoType() == OneDriveItem || info.infoType() == SharePointLibrary { if info.isDriveItem() {
if info.OneDrive == nil && info.SharePoint == nil && info.Groups == nil {
return entry, clues.New("item is not Groups, SharePoint or OneDrive type")
}
// clean metadata suffixes from item refs // clean metadata suffixes from item refs
entry.ItemRef = withoutMetadataSuffix(entry.ItemRef) entry.ItemRef = withoutMetadataSuffix(entry.ItemRef)
} }

View File

@ -182,3 +182,14 @@ func (i ItemInfo) updateFolder(f *FolderInfo) error {
return clues.New("unsupported type") return clues.New("unsupported type")
} }
} }
// true if the info represents an item backed by the drive api.
func (i ItemInfo) isDriveItem() bool {
iit := i.infoType()
if !(iit == OneDriveItem || iit == SharePointLibrary) {
return false
}
return !(i.OneDrive == nil && i.SharePoint == nil && i.Groups == nil)
}

View File

@ -0,0 +1,86 @@
package details
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/tester"
)
type ItemInfoUnitSuite struct {
tester.Suite
}
func TestItemInfoUnitSuite(t *testing.T) {
suite.Run(t, &ItemInfoUnitSuite{Suite: tester.NewUnitSuite(t)})
}
func (suite *ItemInfoUnitSuite) TestItemInfo_IsDriveItem() {
table := []struct {
name string
ii ItemInfo
expect assert.BoolAssertionFunc
}{
{
name: "onedrive item",
ii: ItemInfo{
OneDrive: &OneDriveInfo{
ItemType: OneDriveItem,
},
},
expect: assert.True,
},
{
name: "sharepoint library",
ii: ItemInfo{
SharePoint: &SharePointInfo{
ItemType: SharePointLibrary,
},
},
expect: assert.True,
},
{
name: "sharepoint page",
ii: ItemInfo{
SharePoint: &SharePointInfo{
ItemType: SharePointPage,
},
},
expect: assert.False,
},
{
name: "groups library",
ii: ItemInfo{
Groups: &GroupsInfo{
ItemType: SharePointLibrary,
},
},
expect: assert.True,
},
{
name: "groups channel message",
ii: ItemInfo{
Groups: &GroupsInfo{
ItemType: GroupsChannelMessage,
},
},
expect: assert.False,
},
{
name: "exchange anything",
ii: ItemInfo{
Groups: &GroupsInfo{
ItemType: ExchangeMail,
},
},
expect: assert.False,
},
}
for _, test := range table {
suite.Run(test.name, func() {
test.expect(suite.T(), test.ii.isDriveItem())
})
}
}

View File

@ -16,7 +16,6 @@ import (
"github.com/alcionai/corso/src/internal/kopia" "github.com/alcionai/corso/src/internal/kopia"
"github.com/alcionai/corso/src/internal/m365" "github.com/alcionai/corso/src/internal/m365"
"github.com/alcionai/corso/src/internal/m365/collection/drive/metadata" "github.com/alcionai/corso/src/internal/m365/collection/drive/metadata"
"github.com/alcionai/corso/src/internal/m365/resource"
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/internal/observe" "github.com/alcionai/corso/src/internal/observe"
"github.com/alcionai/corso/src/internal/operations" "github.com/alcionai/corso/src/internal/operations"
@ -768,13 +767,7 @@ func connectToM365(
defer close(progressBar) defer close(progressBar)
} }
// retrieve data from the producer ctrl, err := m365.NewController(ctx, acct, pst, co)
rc := resource.Users
if pst == path.SharePointService {
rc = resource.Sites
}
ctrl, err := m365.NewController(ctx, acct, rc, pst, co)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -259,7 +259,7 @@ func (suite *RepositoryIntegrationSuite) TestNewBackup() {
userID := tconfig.M365UserID(t) userID := tconfig.M365UserID(t)
bo, err := r.NewBackup(ctx, selectors.Selector{DiscreteOwner: userID}) bo, err := r.NewBackup(ctx, selectors.NewExchangeBackup([]string{userID}).Selector)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
require.NotNil(t, bo) require.NotNil(t, bo)
} }
@ -284,7 +284,11 @@ func (suite *RepositoryIntegrationSuite) TestNewRestore() {
ctrlRepo.Retention{}) ctrlRepo.Retention{})
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
ro, err := r.NewRestore(ctx, "backup-id", selectors.Selector{DiscreteOwner: "test"}, restoreCfg) ro, err := r.NewRestore(
ctx,
"backup-id",
selectors.NewExchangeBackup([]string{"test"}).Selector,
restoreCfg)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
require.NotNil(t, ro) require.NotNil(t, ro)
} }
@ -331,7 +335,7 @@ func (suite *RepositoryIntegrationSuite) TestNewBackupAndDelete() {
ro, err := r.NewRestore( ro, err := r.NewRestore(
ctx, ctx,
backupID, backupID,
selectors.Selector{DiscreteOwner: userID}, selectors.NewExchangeBackup([]string{userID}).Selector,
restoreCfg) restoreCfg)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
require.NotNil(t, ro) require.NotNil(t, ro)