Handle deletions of collections in delta query (#2476)
## Description Handle deletion items in delta graph API. ## Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [x] 🕐 Yes, but in a later PR - [ ] ⛔ No ## Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup ## Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * https://github.com/alcionai/corso/issues/2123 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
2a72335716
commit
b174c632b7
@ -69,6 +69,14 @@ type Collection struct {
|
||||
itemMetaReader itemMetaReaderFunc
|
||||
ctrl control.Options
|
||||
|
||||
// PrevPath is the previous hierarchical path used by this collection.
|
||||
// It may be the same as fullPath, if the folder was not renamed or
|
||||
// moved. It will be empty on its first retrieval.
|
||||
prevPath path.Path
|
||||
|
||||
// Specifies if it new, moved/rename or deleted
|
||||
state data.CollectionState
|
||||
|
||||
// should only be true if the old delta token expired
|
||||
doNotMergeItems bool
|
||||
}
|
||||
@ -92,6 +100,7 @@ type itemMetaReaderFunc func(
|
||||
func NewCollection(
|
||||
itemClient *http.Client,
|
||||
folderPath path.Path,
|
||||
prevPath path.Path,
|
||||
driveID string,
|
||||
service graph.Servicer,
|
||||
statusUpdater support.StatusUpdater,
|
||||
@ -102,6 +111,7 @@ func NewCollection(
|
||||
c := &Collection{
|
||||
itemClient: itemClient,
|
||||
folderPath: folderPath,
|
||||
prevPath: prevPath,
|
||||
driveItems: map[string]models.DriveItemable{},
|
||||
driveID: driveID,
|
||||
source: source,
|
||||
@ -109,6 +119,7 @@ func NewCollection(
|
||||
data: make(chan data.Stream, collectionChannelBufferSize),
|
||||
statusUpdater: statusUpdater,
|
||||
ctrl: ctrlOpts,
|
||||
state: data.StateOf(prevPath, folderPath),
|
||||
doNotMergeItems: doNotMergeItems,
|
||||
}
|
||||
|
||||
@ -140,16 +151,12 @@ func (oc *Collection) FullPath() path.Path {
|
||||
return oc.folderPath
|
||||
}
|
||||
|
||||
// TODO(ashmrtn): Fill in with previous path once GraphConnector compares old
|
||||
// and new folder hierarchies.
|
||||
func (oc Collection) PreviousPath() path.Path {
|
||||
return nil
|
||||
return oc.prevPath
|
||||
}
|
||||
|
||||
// TODO(ashmrtn): Fill in once GraphConnector compares old and new folder
|
||||
// hierarchies.
|
||||
func (oc Collection) State() data.CollectionState {
|
||||
return data.NewState
|
||||
return oc.state
|
||||
}
|
||||
|
||||
func (oc Collection) DoNotMergeItems() bool {
|
||||
|
||||
@ -164,6 +164,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() {
|
||||
coll := NewCollection(
|
||||
graph.HTTPClient(graph.NoTimeout()),
|
||||
folderPath,
|
||||
nil,
|
||||
"drive-id",
|
||||
suite,
|
||||
suite.testStatusUpdater(&wg, &collStatus),
|
||||
@ -298,6 +299,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionReadError() {
|
||||
coll := NewCollection(
|
||||
graph.HTTPClient(graph.NoTimeout()),
|
||||
folderPath,
|
||||
nil,
|
||||
"fakeDriveID",
|
||||
suite,
|
||||
suite.testStatusUpdater(&wg, &collStatus),
|
||||
@ -370,6 +372,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionDisablePermissionsBackup() {
|
||||
coll := NewCollection(
|
||||
graph.HTTPClient(graph.NoTimeout()),
|
||||
folderPath,
|
||||
nil,
|
||||
"fakeDriveID",
|
||||
suite,
|
||||
suite.testStatusUpdater(&wg, &collStatus),
|
||||
|
||||
@ -419,7 +419,34 @@ func (c *Collections) UpdateCollections(
|
||||
// the deleted folder/package.
|
||||
delete(newPaths, *item.GetId())
|
||||
|
||||
// TODO(ashmrtn): Create a collection with state Deleted.
|
||||
prevColPath, ok := oldPaths[*item.GetId()]
|
||||
if !ok {
|
||||
// It is possible that an item was created and
|
||||
// deleted between two delta invocations. In
|
||||
// that case, it will only produce a single
|
||||
// delete entry in the delta response.
|
||||
continue
|
||||
}
|
||||
|
||||
prevPath, err := path.FromDataLayerPath(prevColPath, false)
|
||||
if err != nil {
|
||||
logger.Ctx(ctx).Errorw("invalid previous path for deleted item", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
col := NewCollection(
|
||||
c.itemClient,
|
||||
nil,
|
||||
prevPath,
|
||||
driveID,
|
||||
c.service,
|
||||
c.statusUpdater,
|
||||
c.source,
|
||||
c.ctrl,
|
||||
invalidPrevDelta,
|
||||
)
|
||||
|
||||
c.CollectionMap[*item.GetId()] = col
|
||||
|
||||
break
|
||||
}
|
||||
@ -469,6 +496,7 @@ func (c *Collections) UpdateCollections(
|
||||
col = NewCollection(
|
||||
c.itemClient,
|
||||
collectionPath,
|
||||
nil,
|
||||
driveID,
|
||||
c.service,
|
||||
c.statusUpdater,
|
||||
|
||||
@ -24,17 +24,48 @@ import (
|
||||
"github.com/alcionai/corso/src/pkg/selectors"
|
||||
)
|
||||
|
||||
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string {
|
||||
res := make([]string, 0, len(rest))
|
||||
type statePath struct {
|
||||
state data.CollectionState
|
||||
curPath path.Path
|
||||
prevPath path.Path
|
||||
}
|
||||
|
||||
for _, r := range rest {
|
||||
p, err := GetCanonicalPath(r, tenant, user, OneDriveSource)
|
||||
func getExpectedStatePathGenerator(
|
||||
t *testing.T,
|
||||
tenant, user, base string,
|
||||
) func(data.CollectionState, string) statePath {
|
||||
return func(state data.CollectionState, pth string) statePath {
|
||||
p, err := GetCanonicalPath(base+pth, tenant, user, OneDriveSource)
|
||||
require.NoError(t, err)
|
||||
|
||||
res = append(res, p.String())
|
||||
}
|
||||
var (
|
||||
cp path.Path
|
||||
pp path.Path
|
||||
)
|
||||
|
||||
return res
|
||||
if state == data.NewState {
|
||||
cp = p
|
||||
} else {
|
||||
pp = p
|
||||
}
|
||||
|
||||
return statePath{
|
||||
state: state,
|
||||
curPath: cp,
|
||||
prevPath: pp,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getExpectedPathGenerator(t *testing.T,
|
||||
tenant, user, base string,
|
||||
) func(string) string {
|
||||
return func(path string) string {
|
||||
p, err := GetCanonicalPath(base+path, tenant, user, OneDriveSource)
|
||||
require.NoError(t, err)
|
||||
|
||||
return p.String()
|
||||
}
|
||||
}
|
||||
|
||||
type OneDriveCollectionsSuite struct {
|
||||
@ -100,20 +131,21 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
)
|
||||
|
||||
testBaseDrivePath := fmt.Sprintf(rootDrivePattern, "driveID1")
|
||||
expectedPath := getExpectedPathGenerator(suite.T(), tenant, user, testBaseDrivePath)
|
||||
expectedStatePath := getExpectedStatePathGenerator(suite.T(), tenant, user, testBaseDrivePath)
|
||||
|
||||
tests := []struct {
|
||||
testCase string
|
||||
items []models.DriveItemable
|
||||
inputFolderMap map[string]string
|
||||
scope selectors.OneDriveScope
|
||||
expect assert.ErrorAssertionFunc
|
||||
expectedCollectionIDs []string
|
||||
expectedCollectionPaths []string
|
||||
expectedItemCount int
|
||||
expectedContainerCount int
|
||||
expectedFileCount int
|
||||
expectedMetadataPaths map[string]string
|
||||
expectedExcludes map[string]struct{}
|
||||
testCase string
|
||||
items []models.DriveItemable
|
||||
inputFolderMap map[string]string
|
||||
scope selectors.OneDriveScope
|
||||
expect assert.ErrorAssertionFunc
|
||||
expectedCollectionIDs map[string]statePath
|
||||
expectedItemCount int
|
||||
expectedContainerCount int
|
||||
expectedFileCount int
|
||||
expectedMetadataPaths map[string]string
|
||||
expectedExcludes map[string]struct{}
|
||||
}{
|
||||
{
|
||||
testCase: "Invalid item",
|
||||
@ -133,16 +165,12 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveRootItem("root"),
|
||||
driveItem("file", "file", testBaseDrivePath, "root", true, false, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 1,
|
||||
expectedContainerCount: 1,
|
||||
@ -156,23 +184,14 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveRootItem("root"),
|
||||
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
},
|
||||
expectedItemCount: 1,
|
||||
expectedContainerCount: 1,
|
||||
@ -184,23 +203,14 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveRootItem("root"),
|
||||
driveItem("package", "package", testBaseDrivePath, "root", false, false, true),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"package": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/package",
|
||||
)[0],
|
||||
"package": expectedPath("/package"),
|
||||
},
|
||||
expectedItemCount: 1,
|
||||
expectedContainerCount: 1,
|
||||
@ -216,34 +226,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("fileInFolder", "fileInFolder", testBaseDrivePath+folder, "folder", true, false, false),
|
||||
driveItem("fileInPackage", "fileInPackage", testBaseDrivePath+pkg, "package", true, false, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root", "folder", "package"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
testBaseDrivePath+folder,
|
||||
testBaseDrivePath+pkg,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
"folder": expectedStatePath(data.NewState, folder),
|
||||
"package": expectedStatePath(data.NewState, pkg),
|
||||
},
|
||||
expectedItemCount: 5,
|
||||
expectedFileCount: 3,
|
||||
expectedContainerCount: 3,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"package": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/package",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"package": expectedPath("/package"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -260,36 +256,22 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("fileInFolder2", "fileInFolder2", testBaseDrivePath+folderSub+folder, "folder2", true, false, false),
|
||||
driveItem("fileInFolderPackage", "fileInPackage", testBaseDrivePath+pkg, "package", true, false, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder"})[0],
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"folder", "subfolder", "folder2"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
testBaseDrivePath+folderSub,
|
||||
testBaseDrivePath+folderSub+folder,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder"})[0],
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"folder": expectedStatePath(data.NewState, folder),
|
||||
"subfolder": expectedStatePath(data.NewState, folderSub),
|
||||
"folder2": expectedStatePath(data.NewState, folderSub+folder),
|
||||
},
|
||||
expectedItemCount: 4,
|
||||
expectedFileCount: 2,
|
||||
expectedContainerCount: 3,
|
||||
// just "folder" isn't added here because the include check is done on the
|
||||
// parent path since we only check later if something is a folder or not.
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder",
|
||||
)[0],
|
||||
"folder2": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPath("/folder/subfolder"),
|
||||
"folder2": expectedPath("/folder/subfolder/folder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -309,25 +291,16 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: (&selectors.OneDriveBackup{}).
|
||||
Folders([]string{"/folder/subfolder"}, selectors.PrefixMatch())[0],
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"subfolder", "folder2"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+folderSub,
|
||||
testBaseDrivePath+folderSub+folder,
|
||||
),
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"subfolder": expectedStatePath(data.NewState, folderSub),
|
||||
"folder2": expectedStatePath(data.NewState, folderSub+folder),
|
||||
},
|
||||
expectedItemCount: 2,
|
||||
expectedFileCount: 1,
|
||||
expectedContainerCount: 2,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder2": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder/folder",
|
||||
)[0],
|
||||
"folder2": expectedPath("/folder/subfolder/folder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -343,16 +316,12 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("fileInSubfolder", "fileInSubfolder", testBaseDrivePath+folderSub, "subfolder", true, false, false),
|
||||
driveItem("fileInPackage", "fileInPackage", testBaseDrivePath+pkg, "package", true, false, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder/subfolder"})[0],
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"subfolder"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+folderSub,
|
||||
),
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder/subfolder"})[0],
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"subfolder": expectedStatePath(data.NewState, folderSub),
|
||||
},
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 1,
|
||||
expectedContainerCount: 1,
|
||||
@ -367,44 +336,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/folder/subfolder"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 1,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/folder/subfolder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -415,44 +360,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/a-folder"),
|
||||
"subfolder": expectedPath("/a-folder/subfolder"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 1,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/folder/subfolder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -464,44 +385,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/a-folder"),
|
||||
"subfolder": expectedPath("/a-folder/subfolder"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
expectedItemCount: 2,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 1,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/subfolder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -513,44 +410,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/a-folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/a-folder"),
|
||||
"subfolder": expectedPath("/a-folder/subfolder"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
expectedItemCount: 2,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 1,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/subfolder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -562,27 +435,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
delItem("package", testBaseDrivePath, "root", false, false, true),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"package": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/package",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"package": expectedPath("/package"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionPaths: []string{},
|
||||
expectedItemCount: 0,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 0,
|
||||
expectedMetadataPaths: map[string]string{},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"folder": expectedStatePath(data.DeletedState, folder),
|
||||
"package": expectedStatePath(data.DeletedState, pkg),
|
||||
},
|
||||
expectedItemCount: 0,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 0,
|
||||
expectedMetadataPaths: map[string]string{},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
{
|
||||
testCase: "delete folder tree move subfolder",
|
||||
@ -592,38 +458,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{
|
||||
"folder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder",
|
||||
)[0],
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/folder/subfolder",
|
||||
)[0],
|
||||
"folder": expectedPath("/folder"),
|
||||
"subfolder": expectedPath("/folder/subfolder"),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: map[string]statePath{
|
||||
"root": expectedStatePath(data.NewState, ""),
|
||||
"folder": expectedStatePath(data.DeletedState, folder),
|
||||
},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionIDs: []string{"root"},
|
||||
expectedCollectionPaths: expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath,
|
||||
),
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 0,
|
||||
expectedContainerCount: 1,
|
||||
expectedMetadataPaths: map[string]string{
|
||||
"subfolder": expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
testBaseDrivePath+"/subfolder",
|
||||
)[0],
|
||||
"subfolder": expectedPath("/subfolder"),
|
||||
},
|
||||
expectedExcludes: map[string]struct{}{},
|
||||
},
|
||||
@ -632,14 +480,13 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
items: []models.DriveItemable{
|
||||
delItem("item", testBaseDrivePath, "root", true, false, false),
|
||||
},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedCollectionPaths: []string{},
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 1,
|
||||
expectedContainerCount: 0,
|
||||
expectedMetadataPaths: map[string]string{},
|
||||
inputFolderMap: map[string]string{},
|
||||
scope: anyFolder,
|
||||
expect: assert.NoError,
|
||||
expectedItemCount: 1,
|
||||
expectedFileCount: 1,
|
||||
expectedContainerCount: 0,
|
||||
expectedMetadataPaths: map[string]string{},
|
||||
expectedExcludes: map[string]struct{}{
|
||||
"item": {},
|
||||
},
|
||||
@ -675,17 +522,16 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
||||
false,
|
||||
)
|
||||
tt.expect(t, err)
|
||||
assert.Equal(t, len(tt.expectedCollectionIDs), len(c.CollectionMap), "collection ids")
|
||||
assert.Equal(t, len(tt.expectedCollectionIDs), len(c.CollectionMap), "total collections")
|
||||
assert.Equal(t, tt.expectedItemCount, c.NumItems, "item count")
|
||||
assert.Equal(t, tt.expectedFileCount, c.NumFiles, "file count")
|
||||
assert.Equal(t, tt.expectedContainerCount, c.NumContainers, "container count")
|
||||
|
||||
for _, collPath := range tt.expectedCollectionIDs {
|
||||
assert.Contains(t, c.CollectionMap, collPath)
|
||||
}
|
||||
|
||||
for _, col := range c.CollectionMap {
|
||||
assert.Contains(t, tt.expectedCollectionPaths, col.FullPath().String())
|
||||
for id, sp := range tt.expectedCollectionIDs {
|
||||
assert.Contains(t, c.CollectionMap, id, "contains collection with id")
|
||||
assert.Equal(t, sp.state, c.CollectionMap[id].State(), "state for collection")
|
||||
assert.Equal(t, sp.curPath, c.CollectionMap[id].FullPath(), "current path for collection")
|
||||
assert.Equal(t, sp.prevPath, c.CollectionMap[id].PreviousPath(), "prev path for collection")
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.expectedMetadataPaths, outputFolderMap)
|
||||
@ -1129,31 +975,14 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
|
||||
driveBasePath1 := fmt.Sprintf(rootDrivePattern, driveID1)
|
||||
driveBasePath2 := fmt.Sprintf(rootDrivePattern, driveID2)
|
||||
|
||||
rootFolderPath1 := expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1,
|
||||
)[0]
|
||||
folderPath1 := expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1+"/folder",
|
||||
)[0]
|
||||
expectedPath1 := getExpectedPathGenerator(suite.T(), tenant, user, driveBasePath1)
|
||||
expectedPath2 := getExpectedPathGenerator(suite.T(), tenant, user, driveBasePath2)
|
||||
|
||||
rootFolderPath2 := expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath2,
|
||||
)[0]
|
||||
folderPath2 := expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath2+"/folder",
|
||||
)[0]
|
||||
rootFolderPath1 := expectedPath1("")
|
||||
folderPath1 := expectedPath1("/folder")
|
||||
|
||||
rootFolderPath2 := expectedPath2("")
|
||||
folderPath2 := expectedPath2("/folder")
|
||||
|
||||
table := []struct {
|
||||
name string
|
||||
@ -1212,12 +1041,7 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
|
||||
},
|
||||
errCheck: assert.NoError,
|
||||
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1,
|
||||
)[0]: {data.NewState: {"file"}},
|
||||
expectedPath1(""): {data.NewState: {"file"}},
|
||||
},
|
||||
expectedDeltaURLs: map[string]string{
|
||||
driveID1: delta,
|
||||
@ -1405,12 +1229,7 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
|
||||
},
|
||||
errCheck: assert.NoError,
|
||||
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1,
|
||||
)[0]: {data.NewState: {"file"}},
|
||||
expectedPath1(""): {data.NewState: {"file"}},
|
||||
},
|
||||
expectedDeltaURLs: map[string]string{
|
||||
driveID1: delta,
|
||||
@ -1450,18 +1269,8 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
|
||||
},
|
||||
errCheck: assert.NoError,
|
||||
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1,
|
||||
)[0]: {data.NewState: {"file", "folder"}},
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1+"/folder",
|
||||
)[0]: {data.NewState: {"file"}},
|
||||
expectedPath1(""): {data.NewState: {"file", "folder"}},
|
||||
expectedPath1("/folder"): {data.NewState: {"file"}},
|
||||
},
|
||||
expectedDeltaURLs: map[string]string{
|
||||
driveID1: delta,
|
||||
@ -1496,18 +1305,8 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
|
||||
},
|
||||
errCheck: assert.NoError,
|
||||
expectedCollections: map[string]map[data.CollectionState][]string{
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1,
|
||||
)[0]: {data.NewState: {"file", "folder"}},
|
||||
expectedPathAsSlice(
|
||||
suite.T(),
|
||||
tenant,
|
||||
user,
|
||||
driveBasePath1+"/folder",
|
||||
)[0]: {data.NewState: {"file"}},
|
||||
expectedPath1(""): {data.NewState: {"file", "folder"}},
|
||||
expectedPath1("/folder"): {data.NewState: {"file"}},
|
||||
},
|
||||
expectedDeltaURLs: map[string]string{
|
||||
driveID1: delta,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user