aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/dir_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/pkg/dir_test.go')
-rw-r--r--internal/pkg/dir_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/pkg/dir_test.go b/internal/pkg/dir_test.go
new file mode 100644
index 00000000..2e3b9079
--- /dev/null
+++ b/internal/pkg/dir_test.go
@@ -0,0 +1,47 @@
+package pkg_test
+
+import (
+ "io/fs"
+ "testing"
+ "testing/fstest"
+
+ "hakurei.app/internal/pkg"
+)
+
+func TestFlatten(t *testing.T) {
+ t.Parallel()
+
+ testCases := []struct {
+ name string
+ fsys fs.FS
+ want pkg.Checksum
+ }{
+ {"sample cache file", fstest.MapFS{
+ ".": {Mode: 020000000700},
+
+ "checksum": {Mode: 020000000700},
+ "checksum/vsAhtPNo4waRNOASwrQwcIPTqb3SBuJOXw2G4T1mNmVZM-wrQTRllmgXqcIIoRcX": {Mode: 0400, Data: []byte{0x0}},
+ "checksum/0bSFPu5Tnd-2Jj0Mv6co23PW2t3BmHc7eLFj9TgY3eIBg8zislo7xZYNBqovVLcq": {Mode: 0400, Data: []byte{0x0, 0x0, 0x0, 0x0, 0xad, 0xb, 0x0, 0x4, 0xfe, 0xfe, 0x0, 0x0, 0xfe, 0xca, 0x0, 0x0}},
+
+ "identifier": {Mode: 020000000700},
+ "identifier/vsAhtPNo4waRNOASwrQwcIPTqb3SBuJOXw2G4T1mNmVZM-wrQTRllmgXqcIIoRcX": {Mode: 0400, Data: []byte{0x0}},
+ "identifier/0bSFPu5Tnd-2Jj0Mv6co23PW2t3BmHc7eLFj9TgY3eIBg8zislo7xZYNBqovVLcq": {Mode: 0400, Data: []byte{0x0, 0x0, 0x0, 0x0, 0xad, 0xb, 0x0, 0x4, 0xfe, 0xfe, 0x0, 0x0, 0xfe, 0xca, 0x0, 0x0}},
+ "identifier/cafebabecafebabecafebabecafebabecafebabecafebabecafebabecafebabe": {Mode: 0400, Data: []byte{0x0, 0x0, 0x0, 0x0, 0xad, 0xb, 0x0, 0x4, 0xfe, 0xfe, 0x0, 0x0, 0xfe, 0xca, 0x0, 0x0}},
+ "identifier/deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef": {Mode: 0400, Data: []byte{0x0, 0x0, 0x0, 0x0, 0xad, 0xb, 0x0, 0x4, 0xfe, 0xfe, 0x0, 0x0, 0xfe, 0xca, 0x0, 0x0}},
+ }, pkg.MustDecode("lvK4lY9bQUFscHpxqHmiPvptjUwOgn3BFhzCXZMeupkY1n22WUPSuh7pswEvVZrx")},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ if got, err := pkg.HashFS(tc.fsys, "."); err != nil {
+ t.Fatalf("HashFS: error = %v", err)
+ } else if got != tc.want {
+ t.Fatalf("HashFS: %v", &pkg.ChecksumMismatchError{
+ Got: got,
+ Want: tc.want,
+ })
+ }
+ })
+ }
+}