Metadata: Cache ExifTool JSON by original file hash #755 #759

This commit is contained in:
Michael Mayer
2020-12-30 13:33:47 +01:00
parent b0ed54dd11
commit 8cfabe3205
12 changed files with 337 additions and 235 deletions

44
pkg/fs/cache_test.go Normal file
View File

@@ -0,0 +1,44 @@
package fs
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCachePath(t *testing.T) {
t.Run("error", func(t *testing.T) {
result, err := CachePath("/foo/bar", "123", "baz", false)
assert.Equal(t, "", result)
assert.EqualError(t, err, "cache: hash '123' is too short")
})
t.Run("1234567890abcdef", func(t *testing.T) {
result, err := CachePath("/foo/bar", "1234567890abcdef", "baz", false)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "/foo/bar/baz/1/2/3", result)
})
t.Run("create", func(t *testing.T) {
ns := "pkg_fs_test"
result, err := CachePath(os.TempDir(), "1234567890abcdef", ns, true)
if err != nil {
t.Fatal(err)
}
expected := filepath.Join(os.TempDir(), ns, "1", "2", "3")
assert.Equal(t, expected, result)
assert.DirExists(t, expected)
_ = os.Remove(expected)
})
}