Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: golden/go/filediffstore/filediffstore_test.go

Issue 1401563003: Enable clear/purge for failed digests (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Added unit test to FileDiffStore Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « golden/go/filediffstore/filediffstore.go ('k') | golden/go/mocks/mocks.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: golden/go/filediffstore/filediffstore_test.go
diff --git a/golden/go/filediffstore/filediffstore_test.go b/golden/go/filediffstore/filediffstore_test.go
index 20fc935fb31f84a08530d54de92b060d1f200a68..4b6fa89bcf4e0229ac95e24ee07ef3a15832f1dc 100644
--- a/golden/go/filediffstore/filediffstore_test.go
+++ b/golden/go/filediffstore/filediffstore_test.go
@@ -10,6 +10,7 @@ import (
"time"
assert "github.com/stretchr/testify/require"
+ "go.skia.org/infra/go/fileutil"
"go.skia.org/infra/go/testutils"
"go.skia.org/infra/golden/go/diff"
)
@@ -167,6 +168,12 @@ func assertFileExists(filePath string, t *testing.T) {
}
}
+func assertFileNotExists(filePath string, t *testing.T) {
+ _, err := os.Stat(filePath)
+ assert.NotNil(t, err)
+ assert.True(t, os.IsNotExist(err))
+}
+
func TestAbsPath(t *testing.T) {
fds := getTestFileDiffStore(t, TESTDATA_DIR, true)
@@ -354,3 +361,43 @@ func TestReuseSameInstance(t *testing.T) {
assert.Equal(t, filepath.Join(fds.localImgDir, fmt.Sprintf("%s.%s", TEST_DIGEST1, IMG_EXTENSION)), digestToPaths[TEST_DIGEST1])
assert.Equal(t, filepath.Join(fds.localImgDir, fmt.Sprintf("%s.%s", TEST_DIGEST2, IMG_EXTENSION)), digestToPaths[TEST_DIGEST2])
}
+
+func TestPurgeDigests(t *testing.T) {
+ fds := getTestFileDiffStore(t, TESTDATA_DIR, true)
+ _, err := fds.Get(TEST_DIGEST1, []string{TEST_DIGEST2, TEST_DIGEST3})
+ assert.Nil(t, err)
+ _, err = fds.Get(TEST_DIGEST2, []string{TEST_DIGEST1, TEST_DIGEST3})
+ assert.Nil(t, err)
+
+ d_12 := getDiffBasename(TEST_DIGEST1, TEST_DIGEST2)
+ d_13 := getDiffBasename(TEST_DIGEST1, TEST_DIGEST3)
+ d_23 := getDiffBasename(TEST_DIGEST2, TEST_DIGEST3)
+ assertFileExists(fds.getDiffMetricPath(d_12), t)
+ assertFileExists(fds.getDiffMetricPath(d_13), t)
+ assertFileExists(fds.getDiffMetricPath(d_23), t)
+
+ assert.Nil(t, fds.PurgeDigests([]string{TEST_DIGEST1}, false))
+ // Removed from image cache
+ assertFileNotExists(fileutil.TwoLevelRadixPath(fds.localImgDir, fds.getImageBaseName(TEST_DIGEST1)), t)
+ assertFileExists(fileutil.TwoLevelRadixPath(fds.localImgDir, fds.getImageBaseName(TEST_DIGEST2)), t)
+ assertFileExists(fileutil.TwoLevelRadixPath(fds.localImgDir, fds.getImageBaseName(TEST_DIGEST3)), t)
+
+ // Removed from diffMetrics caches
+ assertFileNotExists(fds.getDiffMetricPath(d_12), t)
+ assertFileNotExists(fds.getDiffMetricPath(d_13), t)
+ assertFileExists(fds.getDiffMetricPath(d_23), t)
+ _, ok := fds.diffCache.Get(d_12)
+ assert.False(t, ok)
+ _, ok = fds.diffCache.Get(d_13)
+ assert.False(t, ok)
+ _, ok = fds.diffCache.Get(d_23)
+ assert.True(t, ok)
+
+ // Removed from cache
+ _, ok = fds.imageCache.Get(TEST_DIGEST1)
+ assert.False(t, ok)
+ _, ok = fds.imageCache.Get(TEST_DIGEST2)
+ assert.True(t, ok)
+ _, ok = fds.imageCache.Get(TEST_DIGEST3)
+ assert.True(t, ok)
+}
« no previous file with comments | « golden/go/filediffstore/filediffstore.go ('k') | golden/go/mocks/mocks.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698