mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-07-26 10:38:43 +00:00
add test case to check error scenario
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user