aboutsummaryrefslogtreecommitdiff
path: root/internal/compress
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-05 21:33:12 +0800
committerGravatar Runxi Yu2026-03-05 21:33:12 +0800
commitc0e3ca8389d3692f24b35b5f8bc4022ae712d141 (patch)
tree72f8e9883e85cbc365c47f4ef2af739a91d73551 /internal/compress
parentinternal/compress/zlib: Fix testpkg (diff)
signatureNo signature
*: I guess os.Root is alright for tests too *shrug*
Diffstat (limited to 'internal/compress')
-rw-r--r--internal/compress/zlib/writer_test.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/internal/compress/zlib/writer_test.go b/internal/compress/zlib/writer_test.go
index f3bfb437..e67a3539 100644
--- a/internal/compress/zlib/writer_test.go
+++ b/internal/compress/zlib/writer_test.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
+ "path/filepath"
"testing"
"codeberg.org/lindenii/furgit/internal/compress/zlib"
@@ -24,29 +25,35 @@ var data = []string{
"test a reasonable sized string that can be compressed",
}
+func testdataRoot(t *testing.T) *os.Root {
+ t.Helper()
+
+ root, err := os.OpenRoot("../testdata")
+ if err != nil {
+ t.Fatalf("open testdata root: %v", err)
+ }
+
+ return root
+}
+
// Tests that compressing and then decompressing the given file at the given compression level and dictionary
// yields equivalent bytes to the original file.
func testFileLevelDict(t *testing.T, fn string, level int, d string) {
t.Helper()
- // Read the file, as golden output.
- golden, err := os.Open(fn)
- if err != nil {
- t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
-
- return
- }
+ root := testdataRoot(t)
defer func() {
- err := golden.Close()
+ err := root.Close()
if err != nil {
- t.Fatalf("%s (level=%d, dict=%q): close golden: %v", fn, level, d, err)
+ t.Fatalf("%s (level=%d, dict=%q): close testdata root: %v", fn, level, d, err)
}
}()
- b0, err0 := io.ReadAll(golden)
- if err0 != nil {
- t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err0)
+ // Read the file, as golden output.
+ b0, err := root.ReadFile(filepath.Base(fn))
+ if err != nil {
+ t.Errorf("%s (level=%d, dict=%q): %v", fn, level, d, err)
return
}