Add integration test for delta token usage
This commit is contained in:
parent
9af64f8c13
commit
22dfe085bf
@ -1,6 +1,7 @@
|
|||||||
package onedrive
|
package onedrive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -89,10 +90,37 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
|||||||
|
|
||||||
nfid := ptr.Val(newFolder.GetId())
|
nfid := ptr.Val(newFolder.GetId())
|
||||||
|
|
||||||
|
collectorFunc := func(
|
||||||
|
ctx context.Context,
|
||||||
|
driveID, driveName string,
|
||||||
|
driveItems []models.DriveItemable,
|
||||||
|
oldPaths map[string]string,
|
||||||
|
newPaths map[string]string,
|
||||||
|
excluded map[string]struct{},
|
||||||
|
itemCollection map[string]map[string]string,
|
||||||
|
doNotMergeItems bool,
|
||||||
|
errs *fault.Bus,
|
||||||
|
) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the previous delta to feed into url cache
|
||||||
|
prevDelta, _, _, err := collectItems(
|
||||||
|
ctx,
|
||||||
|
suite.ac.Drives().NewItemPager(driveID, "", api.DriveItemSelectDefault()),
|
||||||
|
suite.driveID,
|
||||||
|
"drive-name",
|
||||||
|
collectorFunc,
|
||||||
|
map[string]string{},
|
||||||
|
"",
|
||||||
|
fault.New(true))
|
||||||
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
require.NotNil(t, prevDelta.URL)
|
||||||
|
|
||||||
// Create a bunch of files in the new folder
|
// Create a bunch of files in the new folder
|
||||||
var items []models.DriveItemable
|
var items []models.DriveItemable
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
newItemName := "test_url_cache_basic_" + dttm.FormatNow(dttm.SafeForTesting)
|
newItemName := "test_url_cache_basic_" + dttm.FormatNow(dttm.SafeForTesting)
|
||||||
|
|
||||||
item, err := ac.Drives().PostItemInContainer(
|
item, err := ac.Drives().PostItemInContainer(
|
||||||
@ -110,13 +138,12 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new URL cache with a long TTL
|
// Create a new URL cache with a long TTL
|
||||||
cache, err := newURLCache(
|
uc, err := newURLCache(
|
||||||
suite.driveID,
|
suite.driveID,
|
||||||
"",
|
prevDelta.URL,
|
||||||
1*time.Hour,
|
1*time.Hour,
|
||||||
driveItemPager,
|
driveItemPager,
|
||||||
fault.New(true))
|
fault.New(true))
|
||||||
|
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
// Launch parallel requests to the cache, one per item
|
// Launch parallel requests to the cache, one per item
|
||||||
@ -128,11 +155,11 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
// Read item from URL cache
|
// Read item from URL cache
|
||||||
props, err := cache.getItemProperties(
|
props, err := uc.getItemProperties(
|
||||||
ctx,
|
ctx,
|
||||||
ptr.Val(items[i].GetId()))
|
ptr.Val(items[i].GetId()))
|
||||||
|
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
require.NotNil(t, props)
|
require.NotNil(t, props)
|
||||||
require.NotEmpty(t, props.downloadURL)
|
require.NotEmpty(t, props.downloadURL)
|
||||||
require.Equal(t, false, props.isDeleted)
|
require.Equal(t, false, props.isDeleted)
|
||||||
@ -146,15 +173,14 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
|||||||
props.downloadURL,
|
props.downloadURL,
|
||||||
nil,
|
nil,
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
// Validate that <= 1 delta queries were made
|
// Validate that <= 1 delta queries were made by url cache
|
||||||
require.LessOrEqual(t, cache.deltaQueryCount, 1)
|
require.LessOrEqual(t, uc.deltaQueryCount, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
type URLCacheUnitSuite struct {
|
type URLCacheUnitSuite struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user