Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-10-28 08:33:09 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-10-29 03:15:07 +0300
commit47a11efd46435fb28c3d5243c5419b0d9dc9c1fe (patch)
tree79bb0af55cd5e0002c7bf6e9bc514e739994ac9c
parent54cabcc8ea107974cf58c093016cab51d773e5c7 (diff)
Update test with configurable refresh
remove commented test
-rw-r--r--internal/vfs/zip/vfs_test.go77
1 files changed, 51 insertions, 26 deletions
diff --git a/internal/vfs/zip/vfs_test.go b/internal/vfs/zip/vfs_test.go
index 2c3e8949..90023144 100644
--- a/internal/vfs/zip/vfs_test.go
+++ b/internal/vfs/zip/vfs_test.go
@@ -132,41 +132,66 @@ func TestVFSArchiveCacheEvict(t *testing.T) {
require.Equal(t, float64(1), archivesCountEnd-archivesCount, "all expired archives are evicted")
}
-func TestVFSFindOrCreateArchiveErrored(t *testing.T) {
+func TestVFSFindOrOpenArchiveRefresh(t *testing.T) {
testServerURL, cleanup := newZipFileServerURL(t, "group/zip.gitlab.io/public.zip", nil)
defer cleanup()
- path := testServerURL + "/unknown.zip"
+ vfs := New(
+ // using defaultCacheExpirationInterval ensures refresh would be called
+ WithCacheRefreshInterval(defaultCacheExpirationInterval),
+ ).(*zipVFS)
- vfs := New().(*zipVFS)
+ tests := map[string]struct {
+ path string
+ expectOpenError bool
+ expectEqualExpiry bool
+ }{
+ "successful_refresh": {path: "/public.zip", expectOpenError: false, expectEqualExpiry: false},
+ "errored_archive": {path: "/unknown.zip", expectOpenError: true, expectEqualExpiry: true},
+ }
- archivesMetric := metrics.ZipCachedEntries.WithLabelValues("archive")
- archivesCount := testutil.ToFloat64(archivesMetric)
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ archivesMetric := metrics.ZipCachedEntries.WithLabelValues("archive")
+ archivesCount := testutil.ToFloat64(archivesMetric)
+
+ path := testServerURL + test.path
+
+ // create a new archive and increase counters
+ archive1, err1 := vfs.findOrOpenArchive(context.Background(), path)
+ if test.expectOpenError {
+ require.Error(t, err1)
+ require.Nil(t, archive1)
+ } else {
+ require.NoError(t, err1)
+ }
- // create a new archive and increase counters
- archive, err := vfs.findOrOpenArchive(context.Background(), path)
- require.Error(t, err)
- require.Nil(t, archive)
+ item1, exp1, found := vfs.cache.GetWithExpiration(path)
+ require.True(t, found)
- item, exp1, found := vfs.cache.GetWithExpiration(path)
- require.True(t, found)
+ // should return errored archive
+ archive2, err2 := vfs.findOrOpenArchive(context.Background(), path)
+ if test.expectOpenError {
+ require.Error(t, err2)
+ require.Nil(t, archive2)
+ } else {
+ require.NoError(t, err2)
+ }
- // item has been opened and has an error
- opened, err1 := item.(*zipArchive).openStatus()
- require.True(t, opened)
- require.Error(t, err1)
- require.Equal(t, err, err1, "same error as findOrOpenArchive")
+ require.Equal(t, err1, err2, "same error for the same archive")
- // should return errored archive
- archive2, err2 := vfs.findOrOpenArchive(context.Background(), path)
- require.Error(t, err2)
- require.Nil(t, archive2)
- require.Equal(t, err1, err2, "same error for the same archive")
+ item2, exp2, found := vfs.cache.GetWithExpiration(path)
+ require.True(t, found)
+ require.Equal(t, item1, item2, "same item is returned")
- _, exp2, found := vfs.cache.GetWithExpiration(path)
- require.True(t, found)
- require.Equal(t, exp1, exp2, "archive has not been refreshed")
+ if test.expectEqualExpiry {
+ require.True(t, exp1.Equal(exp2), "archive has not been refreshed")
+ } else {
+ require.True(t, exp2.After(exp1), "exp2 should be after exp1 due to refresh")
+ }
- archivesCountEnd := testutil.ToFloat64(archivesMetric)
- require.Equal(t, float64(1), archivesCountEnd-archivesCount, "only one archive cached")
+ archivesCountEnd := testutil.ToFloat64(archivesMetric)
+ require.Equal(t, float64(1), archivesCountEnd-archivesCount, "only one archive cached")
+ })
+ }
}