Treat empty prev delta as invalid (#2475)

## Description

Empty delta values are treated as invalid and follow similar rules.

## 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: --->
- [ ] 🌻 Feature
- [x] 🐛 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-10 23:55:21 +05:30 committed by GitHub
parent 66e5e7693d
commit 2a72335716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 4 deletions

View File

@ -1561,8 +1561,33 @@ func (suite *OneDriveCollectionsSuite) TestGet() {
c.drivePagerFunc = drivePagerFunc
c.itemPagerFunc = itemPagerFunc
// TODO(ashmrtn): Allow passing previous metadata.
cols, delList, err := c.Get(ctx, nil)
mc, err := graph.MakeMetadataCollection(
tenant,
user,
path.OneDriveService,
path.FilesCategory,
[]graph.MetadataCollectionEntry{
graph.NewMetadataEntry(
graph.DeltaURLsFileName,
map[string]string{
driveID1: "prev-delta",
driveID2: "prev-delta",
},
),
graph.NewMetadataEntry(
graph.PreviousPathFileName,
map[string]map[string]string{
driveID1: {},
driveID2: {},
},
),
},
func(*support.ConnectorOperationStatus) {},
)
assert.NoError(t, err, "creating metadata collection")
prevMetadata := []data.RestoreCollection{data.NotFoundRestoreCollection{Collection: mc}}
cols, delList, err := c.Get(ctx, prevMetadata)
test.errCheck(t, err)
if err != nil {
@ -1688,12 +1713,14 @@ func getDeltaError() error {
func (suite *OneDriveCollectionsSuite) TestCollectItems() {
next := "next"
delta := "delta"
prevDelta := "prev-delta"
table := []struct {
name string
items []deltaPagerResult
deltaURL string
prevDeltaSuccess bool
prevDelta string
err error
}{
{
@ -1703,6 +1730,16 @@ func (suite *OneDriveCollectionsSuite) TestCollectItems() {
{deltaLink: &delta},
},
prevDeltaSuccess: true,
prevDelta: prevDelta,
},
{
name: "empty prev delta",
deltaURL: delta,
items: []deltaPagerResult{
{deltaLink: &delta},
},
prevDeltaSuccess: false,
prevDelta: "",
},
{
name: "next then delta",
@ -1712,6 +1749,7 @@ func (suite *OneDriveCollectionsSuite) TestCollectItems() {
{deltaLink: &delta},
},
prevDeltaSuccess: true,
prevDelta: prevDelta,
},
{
name: "invalid prev delta",
@ -1720,6 +1758,7 @@ func (suite *OneDriveCollectionsSuite) TestCollectItems() {
{err: getDeltaError()},
{deltaLink: &delta}, // works on retry
},
prevDelta: prevDelta,
prevDeltaSuccess: false,
},
{
@ -1728,6 +1767,7 @@ func (suite *OneDriveCollectionsSuite) TestCollectItems() {
{nextLink: &next},
{err: assert.AnError},
},
prevDelta: prevDelta,
prevDeltaSuccess: true,
err: assert.AnError,
},
@ -1759,7 +1799,7 @@ func (suite *OneDriveCollectionsSuite) TestCollectItems() {
"",
"General",
collectorFunc,
"",
test.prevDelta,
)
require.ErrorIs(suite.T(), err, test.err, "delta fetch err")

View File

@ -194,7 +194,7 @@ func collectItems(
oldPaths = map[string]string{}
newPaths = map[string]string{}
excluded = map[string]struct{}{}
invalidPrevDelta = false
invalidPrevDelta = len(prevDelta) == 0
)
maps.Copy(newPaths, oldPaths)