Skip to content

Commit f6ff417

Browse files
committed
tests: Add test cases for incomplete frames
A simple test case for some frames that are missing data. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
1 parent 46f97db commit f6ff417

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

cobs_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,31 @@ func FuzzChainWriter(f *testing.F) {
291291
})
292292
}
293293

294+
var incompleteFrame = []struct {
295+
name string
296+
data []byte
297+
}{
298+
{
299+
name: "Missing single byte",
300+
data: []byte{0x02},
301+
},
302+
{
303+
name: "2 zeroes and missing end",
304+
data: []byte{0x01, 0x01, 0x05},
305+
},
306+
}
307+
308+
func TestDecodeIncomplete(t *testing.T) {
309+
for _, tc := range incompleteFrame {
310+
t.Run(tc.name, func(t *testing.T) {
311+
_, err := Decode(tc.data)
312+
if err != ErrIncompleteFrame {
313+
t.Errorf("Unexpected decode incomplete error: %v", err)
314+
}
315+
})
316+
}
317+
}
318+
294319
// https://github.com/golang/go/issues/54111
295320
type LimitedWriter struct {
296321
W io.Writer // underlying writer

0 commit comments

Comments
 (0)