diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-01-02 00:59:37 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-01-02 12:57:19 +0900 |
| commit | e9de5d3aca533ec27839661b2d311b4fcb7a13fb (patch) | |
| tree | 31bf9378cef638cbb8dd0d1dfc74c5bc10214300 /internal/pkg/dir_test.go | |
| parent | 993afde840834dbaf4fd46d057e605a806b4a31c (diff) | |
internal/pkg: implement caching for files
This change contains primitives for validating and caching single-file artifacts.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/pkg/dir_test.go')
| -rw-r--r-- | internal/pkg/dir_test.go | 47 |
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, + }) + } + }) + } +} |
