Skip to content

Commit 46f97db

Browse files
committed
tests: Add decoder NeedsMoreData checks to existing test cases
With the introduction of NeedsMoreData we should verify decoder states in the current tests. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 5dbe4e1 commit 46f97db

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cobs_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func TestWriter(t *testing.T) {
166166
for _, tc := range testCases {
167167
t.Run(tc.name, func(t *testing.T) {
168168
buf := bytes.NewBuffer(make([]byte, 0, len(tc.enc)))
169-
e := NewEncoder(NewDecoder(buf))
169+
d := NewDecoder(buf)
170+
e := NewEncoder(d)
170171

171172
n, err := e.Write(tc.dec)
172173
if err != nil {
@@ -176,6 +177,9 @@ func TestWriter(t *testing.T) {
176177
if err != nil {
177178
t.Errorf("writer close error: %v", err)
178179
}
180+
if d.NeedsMoreData() {
181+
t.Error("writer incomplete decode data")
182+
}
179183
if n != len(tc.dec) {
180184
t.Errorf("writer length got %d, want %d", n, len(tc.dec))
181185
}
@@ -220,6 +224,10 @@ func TestStream(t *testing.T) {
220224
t.Error("stream decode EOD missing")
221225
}
222226

227+
if d.NeedsMoreData() {
228+
t.Error("stream decode frame incomplete")
229+
}
230+
223231
if !bytes.Equal(buf.Bytes(), tc.dec) {
224232
t.Errorf("stream decode got %v, want %v", buf.Bytes(), tc.dec)
225233
}
@@ -259,7 +267,8 @@ func FuzzChainWriter(f *testing.F) {
259267
}
260268
f.Fuzz(func(t *testing.T, a []byte) {
261269
var buf bytes.Buffer
262-
e := NewEncoder(NewDecoder(&buf))
270+
d := NewDecoder(&buf)
271+
e := NewEncoder(d)
263272

264273
n, err := e.Write(a)
265274
if err != nil {
@@ -273,6 +282,9 @@ func FuzzChainWriter(f *testing.F) {
273282
if err != nil {
274283
t.Errorf("fuzz chain close error: %v", err)
275284
}
285+
if d.NeedsMoreData() {
286+
t.Error("fuzz chain incomplete decode data")
287+
}
276288
if !bytes.Equal(buf.Bytes(), a) {
277289
t.Errorf("fuzz chain got %v want %v", buf.Bytes(), a)
278290
}

0 commit comments

Comments
 (0)