From 6c410c298c2756c424017c0fcbbaf79f821b27b6 Mon Sep 17 00:00:00 2001 From: Keepers Date: Thu, 11 May 2023 16:46:51 -0600 Subject: [PATCH] consts for drives, root: (#3385) #### Does this PR need a docs update or release note? - [x] :no_entry: No #### Type of change - [x] :broom: Tech Debt/Cleanup #### Test Plan - [x] :zap: Unit test - [x] :green_heart: E2E --- .../graph_connector_onedrive_test.go | 84 +++++++++---------- .../connector/onedrive/consts/consts.go | 10 +++ src/internal/connector/onedrive/drive.go | 3 +- .../operations/backup_integration_test.go | 3 +- src/internal/operations/backup_test.go | 13 +-- src/pkg/backup/details/details_test.go | 15 ++-- src/pkg/path/drive_test.go | 25 ++++-- src/pkg/selectors/onedrive_test.go | 3 +- src/pkg/selectors/sharepoint_test.go | 22 +++-- 9 files changed, 104 insertions(+), 74 deletions(-) create mode 100644 src/internal/connector/onedrive/consts/consts.go diff --git a/src/internal/connector/graph_connector_onedrive_test.go b/src/internal/connector/graph_connector_onedrive_test.go index 0c4c40a47..98ade5372 100644 --- a/src/internal/connector/graph_connector_onedrive_test.go +++ b/src/internal/connector/graph_connector_onedrive_test.go @@ -16,6 +16,7 @@ import ( "github.com/alcionai/corso/src/internal/common/ptr" "github.com/alcionai/corso/src/internal/connector/graph" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/connector/onedrive/metadata" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/version" @@ -109,7 +110,6 @@ var ( folderAName = "folder-a" folderBName = "b" folderNamedFolder = "folder" - rootFolder = "root:" fileAData = []byte(strings.Repeat("a", 33)) fileBData = []byte(strings.Repeat("b", 65)) @@ -255,7 +255,7 @@ func (c *onedriveCollection) withPermissions(perm permData) *onedriveCollection metaName = "" } - if name == rootFolder { + if name == odConsts.RootPathDir { return c } @@ -631,35 +631,35 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions( suite.BackupResourceOwner()) rootPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, } folderAPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, } subfolderBPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, folderBName, } subfolderAPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, folderBName, folderAName, } folderBPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderBName, } @@ -776,34 +776,34 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) { folderCName := "folder-c" rootPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, } folderAPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, } folderBPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderBName, } // For skipped test // subfolderAPath := []string{ - // "drives", + // odConsts.DrivesPathDir, // driveID, - // rootFolder, + // odConsts.RootPathDir, // folderBName, // folderAName, // } folderCPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderCName, } @@ -987,9 +987,9 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) { inputCols := []onedriveColInfo{ { pathElements: []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, }, files: []itemData{ { @@ -1008,9 +1008,9 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) { expectedCols := []onedriveColInfo{ { pathElements: []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, }, files: []itemData{ { @@ -1073,34 +1073,34 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio folderCName := "empty" rootPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, } folderAPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, } subfolderAAPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, folderAName, } subfolderABPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, folderBName, } subfolderACPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderAName, folderCName, } @@ -1246,20 +1246,20 @@ func testRestoreFolderNamedFolderRegression( suite.BackupResourceOwner()) rootPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, } folderFolderPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderNamedFolder, } subfolderPath := []string{ - "drives", + odConsts.DrivesPathDir, driveID, - rootFolder, + odConsts.RootPathDir, folderNamedFolder, folderBName, } diff --git a/src/internal/connector/onedrive/consts/consts.go b/src/internal/connector/onedrive/consts/consts.go new file mode 100644 index 000000000..662354ad6 --- /dev/null +++ b/src/internal/connector/onedrive/consts/consts.go @@ -0,0 +1,10 @@ +package onedrive + +const ( + // const used as the root dir for the drive portion of a path prefix. + // eg: tid/onedrive/ro/files/drives/driveid/... + DrivesPathDir = "drives" + // const used as the root-of-drive dir for the drive portion of a path prefix. + // eg: tid/onedrive/ro/files/drives/driveid/root:/... + RootPathDir = "root:" +) diff --git a/src/internal/connector/onedrive/drive.go b/src/internal/connector/onedrive/drive.go index c499aac05..27bf2091c 100644 --- a/src/internal/connector/onedrive/drive.go +++ b/src/internal/connector/onedrive/drive.go @@ -14,6 +14,7 @@ import ( "github.com/alcionai/corso/src/internal/connector/graph" gapi "github.com/alcionai/corso/src/internal/connector/graph/api" "github.com/alcionai/corso/src/internal/connector/onedrive/api" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/path" @@ -71,7 +72,7 @@ func pathPrefixerForSource( } return func(driveID string) (path.Path, error) { - return path.Build(tenantID, resourceOwner, serv, cat, false, "drives", driveID, "root:") + return path.Build(tenantID, resourceOwner, serv, cat, false, odConsts.DrivesPathDir, driveID, odConsts.RootPathDir) } } diff --git a/src/internal/operations/backup_integration_test.go b/src/internal/operations/backup_integration_test.go index 0b6283078..310036a64 100644 --- a/src/internal/operations/backup_integration_test.go +++ b/src/internal/operations/backup_integration_test.go @@ -29,6 +29,7 @@ import ( "github.com/alcionai/corso/src/internal/connector/mock" "github.com/alcionai/corso/src/internal/connector/onedrive" odapi "github.com/alcionai/corso/src/internal/connector/onedrive/api" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/connector/onedrive/metadata" "github.com/alcionai/corso/src/internal/connector/support" "github.com/alcionai/corso/src/internal/data" @@ -369,7 +370,7 @@ func generateContainerOfItems( switch service { case path.OneDriveService, path.SharePointService: - pathFolders = []string{"drives", driveID, "root:", destFldr} + pathFolders = []string{odConsts.DrivesPathDir, driveID, odConsts.RootPathDir, destFldr} } collections := []incrementalCollection{{ diff --git a/src/internal/operations/backup_test.go b/src/internal/operations/backup_test.go index 1928dfc66..608f6a20a 100644 --- a/src/internal/operations/backup_test.go +++ b/src/internal/operations/backup_test.go @@ -16,6 +16,7 @@ import ( "github.com/alcionai/corso/src/internal/common/prefixmatcher" "github.com/alcionai/corso/src/internal/connector/mock" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/data" evmock "github.com/alcionai/corso/src/internal/events/mock" "github.com/alcionai/corso/src/internal/kopia" @@ -657,15 +658,15 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems path.OneDriveService.String(), ro, path.FilesCategory.String(), - "drives", + odConsts.DrivesPathDir, "drive-id", - "root:", + odConsts.RootPathDir, "work", "item1", }, true, ) - locationPath1 = path.Builder{}.Append("root:", "work-display-name") + locationPath1 = path.Builder{}.Append(odConsts.RootPathDir, "work-display-name") itemPath2 = makePath( suite.T(), []string{ @@ -673,15 +674,15 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_MergeBackupDetails_AddsItems path.OneDriveService.String(), ro, path.FilesCategory.String(), - "drives", + odConsts.DrivesPathDir, "drive-id", - "root:", + odConsts.RootPathDir, "personal", "item2", }, true, ) - locationPath2 = path.Builder{}.Append("root:", "personal-display-name") + locationPath2 = path.Builder{}.Append(odConsts.RootPathDir, "personal-display-name") itemPath3 = makePath( suite.T(), []string{ diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index 7c6466d3c..d6aae6bbc 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common/dttm" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/connector/onedrive/metadata" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/version" @@ -242,9 +243,9 @@ func oneDriveishEntry(t *testing.T, id string, size int, it ItemType) Entry { "tenant-id", "user-id", []string{ - "drives", + odConsts.DrivesPathDir, "drive-id", - "root:", + odConsts.RootPathDir, "Inbox", "folder1", id, @@ -408,7 +409,7 @@ func (suite *DetailsUnitSuite) TestDetailsAdd_LocationFolders() { { ItemInfo: ItemInfo{ Folder: &FolderInfo{ - DisplayName: "root:", + DisplayName: odConsts.RootPathDir, ItemType: FolderItem, DriveName: "drive-name", DriveID: "drive-id", @@ -416,7 +417,7 @@ func (suite *DetailsUnitSuite) TestDetailsAdd_LocationFolders() { }, }, { - LocationRef: "root:", + LocationRef: odConsts.RootPathDir, ItemInfo: ItemInfo{ Folder: &FolderInfo{ DisplayName: "Inbox", @@ -958,7 +959,7 @@ func (suite *DetailsUnitSuite) TestBuilder_Add_shortRefsUniqueFromFolder() { "a-user", []string{ "drive-id", - "root:", + odConsts.RootPathDir, "folder", name + "-id", }) @@ -971,7 +972,7 @@ func (suite *DetailsUnitSuite) TestBuilder_Add_shortRefsUniqueFromFolder() { "a-user", []string{ "drive-id", - "root:", + odConsts.RootPathDir, "folder", name + "-id", name, @@ -1060,7 +1061,7 @@ func (suite *DetailsUnitSuite) TestUpdateItem() { ) newExchangePB := path.Builder{}.Append(folder2) - newOneDrivePB := path.Builder{}.Append("root:", folder2) + newOneDrivePB := path.Builder{}.Append(odConsts.RootPathDir, folder2) table := []struct { name string diff --git a/src/pkg/path/drive_test.go b/src/pkg/path/drive_test.go index 459548db5..5a6853caf 100644 --- a/src/pkg/path/drive_test.go +++ b/src/pkg/path/drive_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/path" ) @@ -22,8 +23,6 @@ func TestOneDrivePathSuite(t *testing.T) { } func (suite *OneDrivePathSuite) Test_ToOneDrivePath() { - const root = "root:" - tests := []struct { name string pathElements []string @@ -32,20 +31,28 @@ func (suite *OneDrivePathSuite) Test_ToOneDrivePath() { }{ { name: "Not enough path elements", - pathElements: []string{"drives", "driveID"}, + pathElements: []string{odConsts.DrivesPathDir, "driveID"}, errCheck: assert.Error, }, { name: "Root path", - pathElements: []string{"drives", "driveID", root}, - expected: &path.DrivePath{DriveID: "driveID", Root: root, Folders: []string{}}, - errCheck: assert.NoError, + pathElements: []string{odConsts.DrivesPathDir, "driveID", odConsts.RootPathDir}, + expected: &path.DrivePath{ + DriveID: "driveID", + Root: odConsts.RootPathDir, + Folders: []string{}, + }, + errCheck: assert.NoError, }, { name: "Deeper path", - pathElements: []string{"drives", "driveID", root, "folder1", "folder2"}, - expected: &path.DrivePath{DriveID: "driveID", Root: root, Folders: []string{"folder1", "folder2"}}, - errCheck: assert.NoError, + pathElements: []string{odConsts.DrivesPathDir, "driveID", odConsts.RootPathDir, "folder1", "folder2"}, + expected: &path.DrivePath{ + DriveID: "driveID", + Root: odConsts.RootPathDir, + Folders: []string{"folder1", "folder2"}, + }, + errCheck: assert.NoError, }, } for _, tt := range tests { diff --git a/src/pkg/selectors/onedrive_test.go b/src/pkg/selectors/onedrive_test.go index f8fe4297d..41835875b 100644 --- a/src/pkg/selectors/onedrive_test.go +++ b/src/pkg/selectors/onedrive_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/alcionai/corso/src/internal/common/dttm" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" @@ -315,7 +316,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveCategory_PathValues() { fileName := "file" fileID := fileName + "-id" shortRef := "short" - elems := []string{"drives", "driveID", "root:", "dir1.d", "dir2.d", fileID} + elems := []string{odConsts.DrivesPathDir, "driveID", odConsts.RootPathDir, "dir1.d", "dir2.d", fileID} filePath, err := path.Build("tenant", "user", path.OneDriveService, path.FilesCategory, true, elems...) require.NoError(t, err, clues.ToCore(err)) diff --git a/src/pkg/selectors/sharepoint_test.go b/src/pkg/selectors/sharepoint_test.go index 63ec7e8ec..2b8f3edf4 100644 --- a/src/pkg/selectors/sharepoint_test.go +++ b/src/pkg/selectors/sharepoint_test.go @@ -12,6 +12,7 @@ import ( "golang.org/x/exp/slices" "github.com/alcionai/corso/src/internal/common/dttm" + odConsts "github.com/alcionai/corso/src/internal/connector/onedrive/consts" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/fault" @@ -223,9 +224,9 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { var ( prefixElems = []string{ - "drives", + odConsts.DrivesPathDir, "drive!id", - "root:", + odConsts.RootPathDir, } itemElems1 = []string{"folderA", "folderB"} itemElems2 = []string{"folderA", "folderC"} @@ -257,7 +258,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { { RepoRef: item, ItemRef: "item", - LocationRef: strings.Join(append([]string{"root:"}, itemElems1...), "/"), + LocationRef: strings.Join(append([]string{odConsts.RootPathDir}, itemElems1...), "/"), ItemInfo: details.ItemInfo{ SharePoint: &details.SharePointInfo{ ItemType: details.SharePointLibrary, @@ -268,7 +269,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { }, { RepoRef: item2, - LocationRef: strings.Join(append([]string{"root:"}, itemElems2...), "/"), + LocationRef: strings.Join(append([]string{odConsts.RootPathDir}, itemElems2...), "/"), // ItemRef intentionally blank to test fallback case ItemInfo: details.ItemInfo{ SharePoint: &details.SharePointInfo{ @@ -281,7 +282,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { { RepoRef: item3, ItemRef: "item3", - LocationRef: strings.Join(append([]string{"root:"}, itemElems3...), "/"), + LocationRef: strings.Join(append([]string{odConsts.RootPathDir}, itemElems3...), "/"), ItemInfo: details.ItemInfo{ SharePoint: &details.SharePointInfo{ ItemType: details.SharePointLibrary, @@ -415,8 +416,15 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() { itemName = "item" itemID = "item-id" shortRef = "short" - driveElems = []string{"drives", "drive!id", "root:.d", "dir1.d", "dir2.d", itemID} - elems = []string{"dir1", "dir2", itemID} + driveElems = []string{ + odConsts.DrivesPathDir, + "drive!id", + odConsts.RootPathDir + ".d", + "dir1.d", + "dir2.d", + itemID, + } + elems = []string{"dir1", "dir2", itemID} ) table := []struct {