Add more tests
This commit is contained in:
parent
01bb562bb5
commit
c13f70ecc7
@ -388,7 +388,11 @@ func (c *Collections) Get(
|
|||||||
if numDriveItems < urlCacheDriveItemThreshold {
|
if numDriveItems < urlCacheDriveItemThreshold {
|
||||||
logger.Ctx(ictx).Info("adding url cache for drive ", driveID)
|
logger.Ctx(ictx).Info("adding url cache for drive ", driveID)
|
||||||
|
|
||||||
err = c.addURLCacheToDriveCollections(ictx, driveID, errs)
|
err = c.addURLCacheToDriveCollections(
|
||||||
|
ictx,
|
||||||
|
driveID,
|
||||||
|
c.handler.ItemPager(driveID, "", api.DriveItemSelectDefault()),
|
||||||
|
errs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -458,13 +462,14 @@ func (c *Collections) Get(
|
|||||||
func (c *Collections) addURLCacheToDriveCollections(
|
func (c *Collections) addURLCacheToDriveCollections(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
driveID string,
|
driveID string,
|
||||||
|
pager api.DriveItemEnumerator,
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
) error {
|
) error {
|
||||||
uc, err := newURLCache(
|
uc, err := newURLCache(
|
||||||
driveID,
|
driveID,
|
||||||
urlCacheRefreshInterval,
|
urlCacheRefreshInterval,
|
||||||
errs,
|
errs,
|
||||||
c.handler.ItemPager(driveID, "", api.DriveItemSelectDefault()))
|
pager)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package onedrive
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -2678,3 +2679,82 @@ func (suite *OneDriveCollectionsUnitSuite) TestCollectItems() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *OneDriveCollectionsUnitSuite) TestURLCacheIntegration() {
|
||||||
|
driveID := "test-drive"
|
||||||
|
collCount := 3
|
||||||
|
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
items []deltaPagerResult
|
||||||
|
deltaURL string
|
||||||
|
prevDeltaSuccess bool
|
||||||
|
prevDelta string
|
||||||
|
err error
|
||||||
|
}{
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "cache is attached",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(test.name, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
c := NewCollections(
|
||||||
|
&itemBackupHandler{api.Drives{}},
|
||||||
|
"test-tenant",
|
||||||
|
"test-user",
|
||||||
|
testFolderMatcher{(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0]},
|
||||||
|
nil,
|
||||||
|
control.Options{ToggleFeatures: control.Toggles{}})
|
||||||
|
|
||||||
|
if _, ok := c.CollectionMap[driveID]; !ok {
|
||||||
|
c.CollectionMap[driveID] = map[string]*Collection{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a few collections
|
||||||
|
for i := 0; i < collCount; i++ {
|
||||||
|
coll, err := NewCollection(
|
||||||
|
&itemBackupHandler{api.Drives{}},
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
driveID,
|
||||||
|
nil,
|
||||||
|
control.Options{ToggleFeatures: control.Toggles{}},
|
||||||
|
CollectionScopeFolder,
|
||||||
|
true,
|
||||||
|
nil)
|
||||||
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
c.CollectionMap[driveID][strconv.Itoa(i)] = coll
|
||||||
|
require.Equal(t, nil, coll.cache, "cache not nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := c.addURLCacheToDriveCollections(
|
||||||
|
ctx,
|
||||||
|
driveID,
|
||||||
|
&mockItemPager{},
|
||||||
|
fault.New(true))
|
||||||
|
|
||||||
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
// Check that all collections have the same cache instance attached
|
||||||
|
// to them
|
||||||
|
var uc *urlCache
|
||||||
|
for _, driveColls := range c.CollectionMap {
|
||||||
|
for _, coll := range driveColls {
|
||||||
|
require.NotNil(t, coll.cache, "cache is nil")
|
||||||
|
if uc == nil {
|
||||||
|
uc = coll.cache.(*urlCache)
|
||||||
|
} else {
|
||||||
|
require.Equal(t, uc, coll.cache, "cache not equal")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user