add test case to check error scenario

This commit is contained in:
2025-10-16 13:10:43 -05:00
parent 1bf0c7c0f0
commit 65947914b3
+32 -1
View File
@@ -3,10 +3,11 @@ package decoders
import (
"fmt"
"reflect"
"strings"
"testing"
)
func TestChunkDecoding(t *testing.T) {
func TestGoodChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
@@ -70,3 +71,33 @@ func TestChunkDecoding(t *testing.T) {
}
}
}
func TestBadChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
errorShouldContain string
}{
{
description: "empty packet",
bytes: []byte{},
errorShouldContain: "must be at least 4 bytes",
},
}
for _, testCase := range testCases {
_, err := DecodeChunk(testCase.bytes)
if err == nil {
t.Errorf("Test '%s' should have failed fail to decode chunk properly", testCase.description)
}
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
t.Errorf("Test '%s' did not return the correct error", testCase.description)
fmt.Printf("expected: %v\n", testCase.errorShouldContain)
fmt.Printf("actual: %v\n", err.Error())
}
}
}