Skip to content

Commit

Permalink
cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmulvey committed Sep 10, 2022
1 parent 69276c7 commit 7d1bc53
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/app/imagedup/hash/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hash

import (
"os"
"testing"

"github.com/kmulvey/path"
"github.com/stretchr/testify/assert"
)

func TestCache(t *testing.T) {
t.Parallel()

var cacheFile = "testcache.json"

var cache, err = NewCache(cacheFile, "TestCache")
assert.NoError(t, err)

files, err := path.ListFiles("../testimages")
assert.NoError(t, err)
var fileNames = path.OnlyNames(path.OnlyFiles(files))

for _, file := range fileNames {
_, err = cache.GetHash(file)
assert.NoError(t, err)
}
assert.Equal(t, 3, cache.NumImages())

_, err = cache.GetHash(fileNames[0])
assert.NoError(t, err)

err = cache.Persist()
assert.NoError(t, err)

// do it again
cache, err = NewCache(cacheFile, "TestCache2")
assert.NoError(t, err)
assert.Equal(t, 3, cache.NumImages())

err = os.RemoveAll(cacheFile)
assert.NoError(t, err)
}

0 comments on commit 7d1bc53

Please sign in to comment.