Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Rename drive handlers to better match uses (#4479)
Browse files Browse the repository at this point in the history
Renames focus on OneDrive and Libraries handlers.
Files are also renamed to match

item -> userDrive
library -> site

If diff is large due to file renames view by
commit since file renames are done in a separate
commit

---

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

#### Issue(s)

* #4254

#### Test Plan

- [ ] 💪 Manual
- [x] ⚡ Unit test
- [x] 💚 E2E
  • Loading branch information
ashmrtn authored Oct 11, 2023
1 parent 7625219 commit ba64f07
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 107 deletions.
12 changes: 6 additions & 6 deletions src/internal/m365/collection/drive/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() {
pkg = "/package"
)

bh := itemBackupHandler{userID: user}
bh := userDriveBackupHandler{userID: user}
testBaseDrivePath := odConsts.DriveFolderPrefixBuilder("driveID1").String()
expectedPath := getExpectedPathGenerator(suite.T(), bh, tenant, testBaseDrivePath)
expectedStatePath := getExpectedStatePathGenerator(suite.T(), bh, tenant, testBaseDrivePath)
Expand Down Expand Up @@ -740,8 +740,8 @@ func (suite *OneDriveCollectionsUnitSuite) TestUpdateCollections() {
maps.Copy(currPrevPaths, test.inputFolderMap)

c := NewCollections(
&itemBackupHandler{
baseItemHandler: baseItemHandler{
&userDriveBackupHandler{
baseUserDriveHandler: baseUserDriveHandler{
ac: api.Drives{},
},
userID: user,
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestGet() {
drive2.SetName(&driveID2)

var (
bh = itemBackupHandler{userID: user}
bh = userDriveBackupHandler{userID: user}

driveBasePath1 = odConsts.DriveFolderPrefixBuilder(driveID1).String()
driveBasePath2 = odConsts.DriveFolderPrefixBuilder(driveID2).String()
Expand Down Expand Up @@ -2468,8 +2468,8 @@ func (suite *OneDriveCollectionsUnitSuite) TestAddURLCacheToDriveCollections() {
// Add a few collections
for i := 0; i < collCount; i++ {
coll, err := NewCollection(
&itemBackupHandler{
baseItemHandler: baseItemHandler{
&userDriveBackupHandler{
baseUserDriveHandler: baseUserDriveHandler{
ac: api.Drives{},
},
userID: "test-user",
Expand Down
6 changes: 3 additions & 3 deletions src/internal/m365/collection/drive/group_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var _ BackupHandler = &groupBackupHandler{}

type groupBackupHandler struct {
libraryBackupHandler
siteBackupHandler
groupID string
scope selectors.GroupsScope
}
Expand All @@ -27,8 +27,8 @@ func NewGroupBackupHandler(
scope selectors.GroupsScope,
) groupBackupHandler {
return groupBackupHandler{
libraryBackupHandler{
baseLibraryHandler: baseLibraryHandler{
siteBackupHandler{
baseSiteHandler: baseSiteHandler{
ac: ac,
},
siteID: siteID,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/m365/collection/drive/group_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (suite *GroupBackupHandlerUnitSuite) TestServiceCat() {
t := suite.T()

s, c := groupBackupHandler{
libraryBackupHandler: libraryBackupHandler{service: path.GroupsService},
siteBackupHandler: siteBackupHandler{service: path.GroupsService},
}.ServiceCat()
assert.Equal(t, path.GroupsService, s)
assert.Equal(t, path.LibrariesCategory, c)
Expand Down
4 changes: 2 additions & 2 deletions src/internal/m365/collection/drive/item_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ func (suite *OneDriveIntgSuite) TestOneDriveNewCollections() {
)

colls := NewCollections(
&itemBackupHandler{
baseItemHandler: baseItemHandler{
&userDriveBackupHandler{
baseUserDriveHandler: baseUserDriveHandler{
ac: suite.ac.Drives(),
},
userID: test.user,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/m365/collection/drive/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (suite *ItemIntegrationSuite) TestItemWriter() {
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
rh := NewRestoreHandler(suite.service.ac)
rh := NewUserDriveRestoreHandler(suite.service.ac)

ctx, flush := tester.NewContext(t)
defer flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
"github.com/alcionai/corso/src/pkg/services/m365/api"
)

type baseLibraryHandler struct {
type baseSiteHandler struct {
ac api.Drives
}

func (h baseLibraryHandler) NewDrivePager(
func (h baseSiteHandler) NewDrivePager(
resourceOwner string,
fields []string,
) api.Pager[models.Driveable] {
return h.ac.NewSiteDrivePager(resourceOwner, fields)
}

func (h baseLibraryHandler) AugmentItemInfo(
func (h baseSiteHandler) AugmentItemInfo(
dii details.ItemInfo,
resource idname.Provider,
item models.DriveItemable,
Expand Down Expand Up @@ -62,23 +62,23 @@ func (h baseLibraryHandler) AugmentItemInfo(
return dii
}

var _ BackupHandler = &libraryBackupHandler{}
var _ BackupHandler = &siteBackupHandler{}

type libraryBackupHandler struct {
baseLibraryHandler
type siteBackupHandler struct {
baseSiteHandler
siteID string
scope selectors.SharePointScope
service path.ServiceType
}

func NewLibraryBackupHandler(
func NewSiteBackupHandler(
ac api.Drives,
siteID string,
scope selectors.SharePointScope,
service path.ServiceType,
) libraryBackupHandler {
return libraryBackupHandler{
baseLibraryHandler: baseLibraryHandler{
) siteBackupHandler {
return siteBackupHandler{
baseSiteHandler: baseSiteHandler{
ac: ac,
},
siteID: siteID,
Expand All @@ -87,15 +87,15 @@ func NewLibraryBackupHandler(
}
}

func (h libraryBackupHandler) Get(
func (h siteBackupHandler) Get(
ctx context.Context,
url string,
headers map[string]string,
) (*http.Response, error) {
return h.ac.Get(ctx, url, headers)
}

func (h libraryBackupHandler) PathPrefix(
func (h siteBackupHandler) PathPrefix(
tenantID, driveID string,
) (path.Path, error) {
return path.Build(
Expand All @@ -109,7 +109,7 @@ func (h libraryBackupHandler) PathPrefix(
odConsts.RootPathDir)
}

func (h libraryBackupHandler) MetadataPathPrefix(
func (h siteBackupHandler) MetadataPathPrefix(
tenantID string,
) (path.Path, error) {
p, err := path.BuildMetadata(
Expand All @@ -125,54 +125,54 @@ func (h libraryBackupHandler) MetadataPathPrefix(
return p, nil
}

func (h libraryBackupHandler) CanonicalPath(
func (h siteBackupHandler) CanonicalPath(
folders *path.Builder,
tenantID string,
) (path.Path, error) {
return folders.ToDataLayerPath(tenantID, h.siteID, h.service, path.LibrariesCategory, false)
}

func (h libraryBackupHandler) ServiceCat() (path.ServiceType, path.CategoryType) {
func (h siteBackupHandler) ServiceCat() (path.ServiceType, path.CategoryType) {
return h.service, path.LibrariesCategory
}

func (h libraryBackupHandler) FormatDisplayPath(
func (h siteBackupHandler) FormatDisplayPath(
driveName string,
pb *path.Builder,
) string {
return "/" + driveName + "/" + pb.String()
}

func (h libraryBackupHandler) NewLocationIDer(
func (h siteBackupHandler) NewLocationIDer(
driveID string,
elems ...string,
) details.LocationIDer {
return details.NewSharePointLocationIDer(driveID, elems...)
}

func (h libraryBackupHandler) GetItemPermission(
func (h siteBackupHandler) GetItemPermission(
ctx context.Context,
driveID, itemID string,
) (models.PermissionCollectionResponseable, error) {
return h.ac.GetItemPermission(ctx, driveID, itemID)
}

func (h libraryBackupHandler) GetItem(
func (h siteBackupHandler) GetItem(
ctx context.Context,
driveID, itemID string,
) (models.DriveItemable, error) {
return h.ac.GetItem(ctx, driveID, itemID)
}

func (h libraryBackupHandler) IsAllPass() bool {
func (h siteBackupHandler) IsAllPass() bool {
return h.scope.IsAny(selectors.SharePointLibraryFolder)
}

func (h libraryBackupHandler) IncludesDir(dir string) bool {
func (h siteBackupHandler) IncludesDir(dir string) bool {
return h.scope.Matches(selectors.SharePointLibraryFolder, dir)
}

func (h libraryBackupHandler) EnumerateDriveItemsDelta(
func (h siteBackupHandler) EnumerateDriveItemsDelta(
ctx context.Context,
driveID, prevDeltaLink string,
selectProps []string,
Expand All @@ -184,46 +184,46 @@ func (h libraryBackupHandler) EnumerateDriveItemsDelta(
// Restore
// ---------------------------------------------------------------------------

var _ RestoreHandler = &libraryRestoreHandler{}
var _ RestoreHandler = &siteRestoreHandler{}

type libraryRestoreHandler struct {
baseLibraryHandler
type siteRestoreHandler struct {
baseSiteHandler
ac api.Client
service path.ServiceType
}

func NewLibraryRestoreHandler(ac api.Client, service path.ServiceType) libraryRestoreHandler {
return libraryRestoreHandler{
baseLibraryHandler: baseLibraryHandler{
func NewSiteRestoreHandler(ac api.Client, service path.ServiceType) siteRestoreHandler {
return siteRestoreHandler{
baseSiteHandler: baseSiteHandler{
ac: ac.Drives(),
},
ac: ac,
service: service,
}
}

func (h libraryRestoreHandler) PostDrive(
func (h siteRestoreHandler) PostDrive(
ctx context.Context,
siteID, driveName string,
) (models.Driveable, error) {
return h.ac.Lists().PostDrive(ctx, siteID, driveName)
}

func (h libraryRestoreHandler) DeleteItem(
func (h siteRestoreHandler) DeleteItem(
ctx context.Context,
driveID, itemID string,
) error {
return h.ac.Drives().DeleteItem(ctx, driveID, itemID)
}

func (h libraryRestoreHandler) DeleteItemPermission(
func (h siteRestoreHandler) DeleteItemPermission(
ctx context.Context,
driveID, itemID, permissionID string,
) error {
return h.ac.Drives().DeleteItemPermission(ctx, driveID, itemID, permissionID)
}

func (h libraryRestoreHandler) GetItemsInContainerByCollisionKey(
func (h siteRestoreHandler) GetItemsInContainerByCollisionKey(
ctx context.Context,
driveID, containerID string,
) (map[string]api.DriveItemIDType, error) {
Expand All @@ -235,30 +235,30 @@ func (h libraryRestoreHandler) GetItemsInContainerByCollisionKey(
return m, nil
}

func (h libraryRestoreHandler) NewItemContentUpload(
func (h siteRestoreHandler) NewItemContentUpload(
ctx context.Context,
driveID, itemID string,
) (models.UploadSessionable, error) {
return h.ac.Drives().NewItemContentUpload(ctx, driveID, itemID)
}

func (h libraryRestoreHandler) PostItemPermissionUpdate(
func (h siteRestoreHandler) PostItemPermissionUpdate(
ctx context.Context,
driveID, itemID string,
body *drives.ItemItemsItemInvitePostRequestBody,
) (drives.ItemItemsItemInviteResponseable, error) {
return h.ac.Drives().PostItemPermissionUpdate(ctx, driveID, itemID, body)
}

func (h libraryRestoreHandler) PostItemLinkShareUpdate(
func (h siteRestoreHandler) PostItemLinkShareUpdate(
ctx context.Context,
driveID, itemID string,
body *drives.ItemItemsItemCreateLinkPostRequestBody,
) (models.Permissionable, error) {
return h.ac.Drives().PostItemLinkShareUpdate(ctx, driveID, itemID, body)
}

func (h libraryRestoreHandler) PostItemInContainer(
func (h siteRestoreHandler) PostItemInContainer(
ctx context.Context,
driveID, parentFolderID string,
newItem models.DriveItemable,
Expand All @@ -267,14 +267,14 @@ func (h libraryRestoreHandler) PostItemInContainer(
return h.ac.Drives().PostItemInContainer(ctx, driveID, parentFolderID, newItem, onCollision)
}

func (h libraryRestoreHandler) GetFolderByName(
func (h siteRestoreHandler) GetFolderByName(
ctx context.Context,
driveID, parentFolderID, folderName string,
) (models.DriveItemable, error) {
return h.ac.Drives().GetFolderByName(ctx, driveID, parentFolderID, folderName)
}

func (h libraryRestoreHandler) GetRootFolder(
func (h siteRestoreHandler) GetRootFolder(
ctx context.Context,
driveID string,
) (models.DriveItemable, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (suite *LibraryBackupHandlerUnitSuite) TestPathPrefix() {
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
h := libraryBackupHandler{service: path.SharePointService, siteID: resourceOwner}
h := siteBackupHandler{service: path.SharePointService, siteID: resourceOwner}

result, err := h.PathPrefix(tenantID, "driveID")
test.expectErr(t, err, clues.ToCore(err))
Expand Down Expand Up @@ -65,7 +65,7 @@ func (suite *LibraryBackupHandlerUnitSuite) TestMetadataPathPrefix() {
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
h := libraryBackupHandler{service: path.SharePointService, siteID: resourceOwner}
h := siteBackupHandler{service: path.SharePointService, siteID: resourceOwner}

result, err := h.MetadataPathPrefix(tenantID)
test.expectErr(t, err, clues.ToCore(err))
Expand Down Expand Up @@ -94,7 +94,7 @@ func (suite *LibraryBackupHandlerUnitSuite) TestCanonicalPath() {
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
h := libraryBackupHandler{service: path.SharePointService, siteID: resourceOwner}
h := siteBackupHandler{service: path.SharePointService, siteID: resourceOwner}
p := path.Builder{}.Append("prefix")

result, err := h.CanonicalPath(p, tenantID)
Expand All @@ -110,7 +110,7 @@ func (suite *LibraryBackupHandlerUnitSuite) TestCanonicalPath() {
func (suite *LibraryBackupHandlerUnitSuite) TestServiceCat() {
t := suite.T()

s, c := libraryBackupHandler{service: path.SharePointService}.ServiceCat()
s, c := siteBackupHandler{service: path.SharePointService}.ServiceCat()
assert.Equal(t, path.SharePointService, s)
assert.Equal(t, path.LibrariesCategory, c)
}
Loading

0 comments on commit ba64f07

Please sign in to comment.