From 34e1f393cb288f952166bb92c6aca926ebae5182 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey Date: Thu, 1 Jun 2023 15:48:07 -0700 Subject: [PATCH] Add soem more tests --- src/internal/m365/onedrive/collection_test.go | 26 ++++++++++++++----- src/internal/m365/onedrive/collections.go | 1 - 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/internal/m365/onedrive/collection_test.go b/src/internal/m365/onedrive/collection_test.go index ba621caf7..b90172ea7 100644 --- a/src/internal/m365/onedrive/collection_test.go +++ b/src/internal/m365/onedrive/collection_test.go @@ -692,7 +692,7 @@ func (suite *GetDriveItemUnitTestSuite) TestDownloadContent() { muc: m, }, { - name: "expired url fetched from cache", + name: "url refreshed from cache", mgi: mock.GetsItem{Item: itemWID, Err: nil}, itemInfo: details.ItemInfo{}, respBody: []io.ReadCloser{nil, iorc}, @@ -710,11 +710,11 @@ func (suite *GetDriveItemUnitTestSuite) TestDownloadContent() { }, }, { - name: "expired url fetched from cache but item deleted", - mgi: mock.GetsItem{Item: itemWID, Err: assert.AnError}, + name: "url refreshed from cache but item deleted", + mgi: mock.GetsItem{Item: itemWID, Err: graph.ErrDeletedInFlight}, itemInfo: details.ItemInfo{}, - respBody: []io.ReadCloser{nil, nil}, - getErr: []error{errUnauth, assert.AnError}, + respBody: []io.ReadCloser{nil, nil, nil}, + getErr: []error{errUnauth, graph.ErrDeletedInFlight, graph.ErrDeletedInFlight}, expectErr: require.Error, expect: require.Nil, muc: &mockURLCache{ @@ -727,6 +727,20 @@ func (suite *GetDriveItemUnitTestSuite) TestDownloadContent() { }, }, }, + { + name: "fallback to item fetch on any cache error", + mgi: mock.GetsItem{Item: itemWID, Err: nil}, + itemInfo: details.ItemInfo{}, + respBody: []io.ReadCloser{nil, iorc}, + getErr: []error{errUnauth, nil}, + expectErr: require.NoError, + expect: require.NotNil, + muc: &mockURLCache{ + Get: func(ctx context.Context, itemID string) (itemProps, error) { + return itemProps{}, assert.AnError + }, + }, + }, } for _, test := range table { suite.Run(test.name, func() { @@ -755,7 +769,7 @@ func (suite *GetDriveItemUnitTestSuite) TestDownloadContent() { mbh, nil, nil, - "drive-id", + driveID, nil, control.Options{ToggleFeatures: control.Toggles{}}, CollectionScopeFolder, diff --git a/src/internal/m365/onedrive/collections.go b/src/internal/m365/onedrive/collections.go index dedf3557b..0fa8ec73e 100644 --- a/src/internal/m365/onedrive/collections.go +++ b/src/internal/m365/onedrive/collections.go @@ -384,7 +384,6 @@ func (c *Collections) Get( numPrevItems = c.NumItems // Only create a drive cache if there are less than 300k items in the drive. - // TODO: Tune this number. Delta query for 300k items takes ~20 mins. if numDriveItems < urlCacheDriveItemThreshold { logger.Ctx(ictx).Info("adding url cache for drive ", driveID)