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:
Abin Simon 2023-02-11 00:26:40 +05:30 committed by GitHub
parent 2a72335716
commit b174c632b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 232 additions and 395 deletions

View File

@ -69,6 +69,14 @@ type Collection struct {
itemMetaReader itemMetaReaderFunc itemMetaReader itemMetaReaderFunc
ctrl control.Options 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 // should only be true if the old delta token expired
doNotMergeItems bool doNotMergeItems bool
} }
@ -92,6 +100,7 @@ type itemMetaReaderFunc func(
func NewCollection( func NewCollection(
itemClient *http.Client, itemClient *http.Client,
folderPath path.Path, folderPath path.Path,
prevPath path.Path,
driveID string, driveID string,
service graph.Servicer, service graph.Servicer,
statusUpdater support.StatusUpdater, statusUpdater support.StatusUpdater,
@ -102,6 +111,7 @@ func NewCollection(
c := &Collection{ c := &Collection{
itemClient: itemClient, itemClient: itemClient,
folderPath: folderPath, folderPath: folderPath,
prevPath: prevPath,
driveItems: map[string]models.DriveItemable{}, driveItems: map[string]models.DriveItemable{},
driveID: driveID, driveID: driveID,
source: source, source: source,
@ -109,6 +119,7 @@ func NewCollection(
data: make(chan data.Stream, collectionChannelBufferSize), data: make(chan data.Stream, collectionChannelBufferSize),
statusUpdater: statusUpdater, statusUpdater: statusUpdater,
ctrl: ctrlOpts, ctrl: ctrlOpts,
state: data.StateOf(prevPath, folderPath),
doNotMergeItems: doNotMergeItems, doNotMergeItems: doNotMergeItems,
} }
@ -140,16 +151,12 @@ func (oc *Collection) FullPath() path.Path {
return oc.folderPath return oc.folderPath
} }
// TODO(ashmrtn): Fill in with previous path once GraphConnector compares old
// and new folder hierarchies.
func (oc Collection) PreviousPath() path.Path { 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 { func (oc Collection) State() data.CollectionState {
return data.NewState return oc.state
} }
func (oc Collection) DoNotMergeItems() bool { func (oc Collection) DoNotMergeItems() bool {

View File

@ -164,6 +164,7 @@ func (suite *CollectionUnitTestSuite) TestCollection() {
coll := NewCollection( coll := NewCollection(
graph.HTTPClient(graph.NoTimeout()), graph.HTTPClient(graph.NoTimeout()),
folderPath, folderPath,
nil,
"drive-id", "drive-id",
suite, suite,
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
@ -298,6 +299,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionReadError() {
coll := NewCollection( coll := NewCollection(
graph.HTTPClient(graph.NoTimeout()), graph.HTTPClient(graph.NoTimeout()),
folderPath, folderPath,
nil,
"fakeDriveID", "fakeDriveID",
suite, suite,
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),
@ -370,6 +372,7 @@ func (suite *CollectionUnitTestSuite) TestCollectionDisablePermissionsBackup() {
coll := NewCollection( coll := NewCollection(
graph.HTTPClient(graph.NoTimeout()), graph.HTTPClient(graph.NoTimeout()),
folderPath, folderPath,
nil,
"fakeDriveID", "fakeDriveID",
suite, suite,
suite.testStatusUpdater(&wg, &collStatus), suite.testStatusUpdater(&wg, &collStatus),

View File

@ -419,7 +419,34 @@ func (c *Collections) UpdateCollections(
// the deleted folder/package. // the deleted folder/package.
delete(newPaths, *item.GetId()) 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 break
} }
@ -469,6 +496,7 @@ func (c *Collections) UpdateCollections(
col = NewCollection( col = NewCollection(
c.itemClient, c.itemClient,
collectionPath, collectionPath,
nil,
driveID, driveID,
c.service, c.service,
c.statusUpdater, c.statusUpdater,

View File

@ -24,17 +24,48 @@ import (
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string { type statePath struct {
res := make([]string, 0, len(rest)) state data.CollectionState
curPath path.Path
for _, r := range rest { prevPath path.Path
p, err := GetCanonicalPath(r, tenant, user, OneDriveSource)
require.NoError(t, err)
res = append(res, p.String())
} }
return res 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)
var (
cp path.Path
pp path.Path
)
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 { type OneDriveCollectionsSuite struct {
@ -100,6 +131,8 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
) )
testBaseDrivePath := fmt.Sprintf(rootDrivePattern, "driveID1") testBaseDrivePath := fmt.Sprintf(rootDrivePattern, "driveID1")
expectedPath := getExpectedPathGenerator(suite.T(), tenant, user, testBaseDrivePath)
expectedStatePath := getExpectedStatePathGenerator(suite.T(), tenant, user, testBaseDrivePath)
tests := []struct { tests := []struct {
testCase string testCase string
@ -107,8 +140,7 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap map[string]string inputFolderMap map[string]string
scope selectors.OneDriveScope scope selectors.OneDriveScope
expect assert.ErrorAssertionFunc expect assert.ErrorAssertionFunc
expectedCollectionIDs []string expectedCollectionIDs map[string]statePath
expectedCollectionPaths []string
expectedItemCount int expectedItemCount int
expectedContainerCount int expectedContainerCount int
expectedFileCount int expectedFileCount int
@ -136,13 +168,9 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 1, expectedFileCount: 1,
expectedContainerCount: 1, expectedContainerCount: 1,
@ -159,20 +187,11 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
}, },
expectedItemCount: 1, expectedItemCount: 1,
expectedContainerCount: 1, expectedContainerCount: 1,
@ -187,20 +206,11 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"package": expectedPathAsSlice( "package": expectedPath("/package"),
suite.T(),
tenant,
user,
testBaseDrivePath+"/package",
)[0],
}, },
expectedItemCount: 1, expectedItemCount: 1,
expectedContainerCount: 1, expectedContainerCount: 1,
@ -219,31 +229,17 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root", "folder", "package"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), "folder": expectedStatePath(data.NewState, folder),
tenant, "package": expectedStatePath(data.NewState, pkg),
user, },
testBaseDrivePath,
testBaseDrivePath+folder,
testBaseDrivePath+pkg,
),
expectedItemCount: 5, expectedItemCount: 5,
expectedFileCount: 3, expectedFileCount: 3,
expectedContainerCount: 3, expectedContainerCount: 3,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "package": expectedPath("/package"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"package": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/package",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -263,33 +259,19 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder"})[0], scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder"})[0],
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"folder", "subfolder", "folder2"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "folder": expectedStatePath(data.NewState, folder),
suite.T(), "subfolder": expectedStatePath(data.NewState, folderSub),
tenant, "folder2": expectedStatePath(data.NewState, folderSub+folder),
user, },
testBaseDrivePath+"/folder",
testBaseDrivePath+folderSub,
testBaseDrivePath+folderSub+folder,
),
expectedItemCount: 4, expectedItemCount: 4,
expectedFileCount: 2, expectedFileCount: 2,
expectedContainerCount: 3, expectedContainerCount: 3,
// just "folder" isn't added here because the include check is done on the // 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. // parent path since we only check later if something is a folder or not.
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"subfolder": expectedPathAsSlice( "subfolder": expectedPath("/folder/subfolder"),
suite.T(), "folder2": expectedPath("/folder/subfolder/folder"),
tenant,
user,
testBaseDrivePath+"/folder/subfolder",
)[0],
"folder2": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder/folder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -310,24 +292,15 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
scope: (&selectors.OneDriveBackup{}). scope: (&selectors.OneDriveBackup{}).
Folders([]string{"/folder/subfolder"}, selectors.PrefixMatch())[0], Folders([]string{"/folder/subfolder"}, selectors.PrefixMatch())[0],
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"subfolder", "folder2"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "subfolder": expectedStatePath(data.NewState, folderSub),
suite.T(), "folder2": expectedStatePath(data.NewState, folderSub+folder),
tenant, },
user,
testBaseDrivePath+folderSub,
testBaseDrivePath+folderSub+folder,
),
expectedItemCount: 2, expectedItemCount: 2,
expectedFileCount: 1, expectedFileCount: 1,
expectedContainerCount: 2, expectedContainerCount: 2,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder2": expectedPathAsSlice( "folder2": expectedPath("/folder/subfolder/folder"),
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder/folder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -346,13 +319,9 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder/subfolder"})[0], scope: (&selectors.OneDriveBackup{}).Folders([]string{"folder/subfolder"})[0],
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"subfolder"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "subfolder": expectedStatePath(data.NewState, folderSub),
suite.T(), },
tenant,
user,
testBaseDrivePath+folderSub,
),
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 1, expectedFileCount: 1,
expectedContainerCount: 1, expectedContainerCount: 1,
@ -367,44 +336,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false), driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 1, expectedContainerCount: 1,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -415,44 +360,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false), driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/a-folder"),
suite.T(), "subfolder": expectedPath("/a-folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/a-folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/a-folder/subfolder",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 1, expectedContainerCount: 1,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -464,44 +385,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false), driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/a-folder"),
suite.T(), "subfolder": expectedPath("/a-folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/a-folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/a-folder/subfolder",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedItemCount: 2, expectedItemCount: 2,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 1, expectedContainerCount: 1,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/subfolder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -513,44 +410,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false), driveItem("folder", "folder", testBaseDrivePath, "root", false, true, false),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/a-folder"),
suite.T(), "subfolder": expectedPath("/a-folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/a-folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/a-folder/subfolder",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), },
tenant,
user,
testBaseDrivePath,
),
expectedItemCount: 2, expectedItemCount: 2,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 1, expectedContainerCount: 1,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/subfolder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -562,22 +435,15 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
delItem("package", testBaseDrivePath, "root", false, false, true), delItem("package", testBaseDrivePath, "root", false, false, true),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "package": expectedPath("/package"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"package": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/package",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionPaths: []string{}, expectedCollectionIDs: map[string]statePath{
"folder": expectedStatePath(data.DeletedState, folder),
"package": expectedStatePath(data.DeletedState, pkg),
},
expectedItemCount: 0, expectedItemCount: 0,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 0, expectedContainerCount: 0,
@ -592,38 +458,20 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false), driveItem("subfolder", "subfolder", testBaseDrivePath, "root", false, true, false),
}, },
inputFolderMap: map[string]string{ inputFolderMap: map[string]string{
"folder": expectedPathAsSlice( "folder": expectedPath("/folder"),
suite.T(), "subfolder": expectedPath("/folder/subfolder"),
tenant,
user,
testBaseDrivePath+"/folder",
)[0],
"subfolder": expectedPathAsSlice(
suite.T(),
tenant,
user,
testBaseDrivePath+"/folder/subfolder",
)[0],
}, },
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionIDs: []string{"root"}, expectedCollectionIDs: map[string]statePath{
expectedCollectionPaths: expectedPathAsSlice( "root": expectedStatePath(data.NewState, ""),
suite.T(), "folder": expectedStatePath(data.DeletedState, folder),
tenant, },
user,
testBaseDrivePath,
),
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 0, expectedFileCount: 0,
expectedContainerCount: 1, expectedContainerCount: 1,
expectedMetadataPaths: map[string]string{ expectedMetadataPaths: map[string]string{
"subfolder": expectedPathAsSlice( "subfolder": expectedPath("/subfolder"),
suite.T(),
tenant,
user,
testBaseDrivePath+"/subfolder",
)[0],
}, },
expectedExcludes: map[string]struct{}{}, expectedExcludes: map[string]struct{}{},
}, },
@ -635,7 +483,6 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
inputFolderMap: map[string]string{}, inputFolderMap: map[string]string{},
scope: anyFolder, scope: anyFolder,
expect: assert.NoError, expect: assert.NoError,
expectedCollectionPaths: []string{},
expectedItemCount: 1, expectedItemCount: 1,
expectedFileCount: 1, expectedFileCount: 1,
expectedContainerCount: 0, expectedContainerCount: 0,
@ -675,17 +522,16 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
false, false,
) )
tt.expect(t, err) 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.expectedItemCount, c.NumItems, "item count")
assert.Equal(t, tt.expectedFileCount, c.NumFiles, "file count") assert.Equal(t, tt.expectedFileCount, c.NumFiles, "file count")
assert.Equal(t, tt.expectedContainerCount, c.NumContainers, "container count") assert.Equal(t, tt.expectedContainerCount, c.NumContainers, "container count")
for _, collPath := range tt.expectedCollectionIDs { for id, sp := range tt.expectedCollectionIDs {
assert.Contains(t, c.CollectionMap, collPath) 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")
for _, col := range c.CollectionMap { assert.Equal(t, sp.prevPath, c.CollectionMap[id].PreviousPath(), "prev path for collection")
assert.Contains(t, tt.expectedCollectionPaths, col.FullPath().String())
} }
assert.Equal(t, tt.expectedMetadataPaths, outputFolderMap) assert.Equal(t, tt.expectedMetadataPaths, outputFolderMap)
@ -1129,31 +975,14 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
driveBasePath1 := fmt.Sprintf(rootDrivePattern, driveID1) driveBasePath1 := fmt.Sprintf(rootDrivePattern, driveID1)
driveBasePath2 := fmt.Sprintf(rootDrivePattern, driveID2) driveBasePath2 := fmt.Sprintf(rootDrivePattern, driveID2)
rootFolderPath1 := expectedPathAsSlice( expectedPath1 := getExpectedPathGenerator(suite.T(), tenant, user, driveBasePath1)
suite.T(), expectedPath2 := getExpectedPathGenerator(suite.T(), tenant, user, driveBasePath2)
tenant,
user,
driveBasePath1,
)[0]
folderPath1 := expectedPathAsSlice(
suite.T(),
tenant,
user,
driveBasePath1+"/folder",
)[0]
rootFolderPath2 := expectedPathAsSlice( rootFolderPath1 := expectedPath1("")
suite.T(), folderPath1 := expectedPath1("/folder")
tenant,
user, rootFolderPath2 := expectedPath2("")
driveBasePath2, folderPath2 := expectedPath2("/folder")
)[0]
folderPath2 := expectedPathAsSlice(
suite.T(),
tenant,
user,
driveBasePath2+"/folder",
)[0]
table := []struct { table := []struct {
name string name string
@ -1212,12 +1041,7 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
}, },
errCheck: assert.NoError, errCheck: assert.NoError,
expectedCollections: map[string]map[data.CollectionState][]string{ expectedCollections: map[string]map[data.CollectionState][]string{
expectedPathAsSlice( expectedPath1(""): {data.NewState: {"file"}},
suite.T(),
tenant,
user,
driveBasePath1,
)[0]: {data.NewState: {"file"}},
}, },
expectedDeltaURLs: map[string]string{ expectedDeltaURLs: map[string]string{
driveID1: delta, driveID1: delta,
@ -1405,12 +1229,7 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
}, },
errCheck: assert.NoError, errCheck: assert.NoError,
expectedCollections: map[string]map[data.CollectionState][]string{ expectedCollections: map[string]map[data.CollectionState][]string{
expectedPathAsSlice( expectedPath1(""): {data.NewState: {"file"}},
suite.T(),
tenant,
user,
driveBasePath1,
)[0]: {data.NewState: {"file"}},
}, },
expectedDeltaURLs: map[string]string{ expectedDeltaURLs: map[string]string{
driveID1: delta, driveID1: delta,
@ -1450,18 +1269,8 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
}, },
errCheck: assert.NoError, errCheck: assert.NoError,
expectedCollections: map[string]map[data.CollectionState][]string{ expectedCollections: map[string]map[data.CollectionState][]string{
expectedPathAsSlice( expectedPath1(""): {data.NewState: {"file", "folder"}},
suite.T(), expectedPath1("/folder"): {data.NewState: {"file"}},
tenant,
user,
driveBasePath1,
)[0]: {data.NewState: {"file", "folder"}},
expectedPathAsSlice(
suite.T(),
tenant,
user,
driveBasePath1+"/folder",
)[0]: {data.NewState: {"file"}},
}, },
expectedDeltaURLs: map[string]string{ expectedDeltaURLs: map[string]string{
driveID1: delta, driveID1: delta,
@ -1496,18 +1305,8 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
}, },
errCheck: assert.NoError, errCheck: assert.NoError,
expectedCollections: map[string]map[data.CollectionState][]string{ expectedCollections: map[string]map[data.CollectionState][]string{
expectedPathAsSlice( expectedPath1(""): {data.NewState: {"file", "folder"}},
suite.T(), expectedPath1("/folder"): {data.NewState: {"file"}},
tenant,
user,
driveBasePath1,
)[0]: {data.NewState: {"file", "folder"}},
expectedPathAsSlice(
suite.T(),
tenant,
user,
driveBasePath1+"/folder",
)[0]: {data.NewState: {"file"}},
}, },
expectedDeltaURLs: map[string]string{ expectedDeltaURLs: map[string]string{
driveID1: delta, driveID1: delta,