diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-08-29 18:58:06 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-08-29 18:58:06 +0900 |
| commit | c2d900ec74e03e9c782cfe7b7ce06ff62cda6601 (patch) | |
| tree | fb13320bfdc62d810aa59769e8809dc2f707919e /pkg/file_test.go | |
| parent | bd4f29909e0750a4660eaf48e3169777a265b0ab (diff) | |
Closes #43.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'pkg/file_test.go')
| -rw-r--r-- | pkg/file_test.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/pkg/file_test.go b/pkg/file_test.go new file mode 100644 index 00000000..5742ca04 --- /dev/null +++ b/pkg/file_test.go @@ -0,0 +1,56 @@ +package pkg_test + +import ( + "io/fs" + "testing" + + "hakurei.app/check" + "hakurei.app/pkg" +) + +func TestFile(t *testing.T) { + t.Parallel() + + want := expectsFile{0} + const ident = "N7M6W8-e55Wky_1q1a6qRKFVDw1S5XtPdB4HE2YZObG8OFum8HittyJgZUG5Ru2u" + wantShebang := expectsFile("#!/bin/sh\n") + const identShebang = "oKTGZb_TRtJf5G1iGGj4SOx1WUbI6YhmsUeEsCNvmK9tZYRwdwQf-DLFUxRPx5qm" + wantELF := expectsFile("\x7fELF\xde\xad\xbe\xef") + const identELF = "LjeHmIJgD1SiXIH8ewpGRed2_LU84NLapstnOAa_0hxLd8YY7x4KM0aApsj-RwCh" + checkWithCache(t, []cacheTestCase{ + {"file", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) { + cureMany(t, c, []cureStep{ + {"short", pkg.NewFile("null", want), base.Append( + "identifier", + ident, + ), want, pkg.WNew, nil}, + + {"shebang", pkg.NewFile("shebang", wantShebang), base.Append( + "identifier", + identShebang, + ), wantShebang, pkg.WNew, nil}, + + {"elf", pkg.NewFile("ELF", wantELF), base.Append( + "identifier", + identELF, + ), wantELF, pkg.WNew, nil}, + }) + }, expectsFS{ + ".": {Mode: fs.ModeDir | 0700}, + + "checksum": {Mode: fs.ModeDir | 0700}, + "checksum/" + pkg.Encode(want.hash()): {Mode: 0400, Data: want}, + "checksum/" + pkg.Encode(wantShebang.hash()): {Mode: 0500, Data: wantShebang}, + "checksum/" + pkg.Encode(wantELF.hash()): {Mode: 0500, Data: wantELF}, + + "identifier": {Mode: fs.ModeDir | 0700}, + "identifier/" + ident: {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/" + pkg.Encode(want.hash()))}, + "identifier/" + identShebang: {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/" + pkg.Encode(wantShebang.hash()))}, + "identifier/" + identELF: {Mode: fs.ModeSymlink | 0777, Data: []byte("../checksum/" + pkg.Encode(wantELF.hash()))}, + + "substitute": {Mode: fs.ModeDir | 0700}, + + "work": {Mode: fs.ModeDir | 0700}, + }}, + }) +} |
