diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-14 18:32:47 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-14 18:32:47 +0900 |
| commit | 8e2d2c8246409dca96cee8589c0d841ef878d802 (patch) | |
| tree | 58d00b08d6b05dac6988a0994cfc0b71988580c7 /ldd/ldd_test.go | |
| parent | 299685775a373bfcf18f03a1c2b7db996ff90267 (diff) | |
ldd: check decoder scan guard
This was unreachable via the Parse wrapper.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd/ldd_test.go')
| -rw-r--r-- | ldd/ldd_test.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/ldd/ldd_test.go b/ldd/ldd_test.go index 0288a7c7..2bacb7aa 100644 --- a/ldd/ldd_test.go +++ b/ldd/ldd_test.go @@ -2,15 +2,22 @@ package ldd_test import ( "encoding/json" - "errors" "reflect" + "strings" "testing" "hakurei.app/container/check" "hakurei.app/ldd" ) -func TestParseError(t *testing.T) { +func TestEntryUnexpectedSegmentsError(t *testing.T) { + const want = `unexpected segments in entry "\x00"` + if got := ldd.EntryUnexpectedSegmentsError("\x00").Error(); got != want { + t.Fatalf("Error: %s, want %s", got, want) + } +} + +func TestDecodeError(t *testing.T) { t.Parallel() testCases := []struct { @@ -38,12 +45,20 @@ meow libzstd.so.1 => /usr/lib/libzstd.so.1 (0x7ff71bfd2000) {"bad location format", ` libzstd.so.1 => /usr/lib/libzstd.so.1 7ff71bfd2000 `, ldd.ErrBadLocationFormat}, + + {"valid", ``, nil}, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { t.Parallel() - if _, err := ldd.Parse([]byte(tc.out)); !errors.Is(err, tc.wantErr) { - t.Errorf("Parse() error = %v, wantErr %v", err, tc.wantErr) + + d := ldd.NewDecoder(strings.NewReader(tc.out)) + + if _, err := d.Decode(); !reflect.DeepEqual(err, tc.wantErr) { + t.Errorf("Decode: error = %v, wantErr %v", err, tc.wantErr) + } + if d.Scan(new(ldd.Entry)) { + t.Fatalf("Scan: unexpected true") } }) } |
