Extend YAMLDecoder Read tests

pull/6/head
Steve Larkin 2017-12-12 19:11:23 +01:00
parent 86d02ac368
commit e913612003
1 changed files with 18 additions and 6 deletions

View File

@ -29,16 +29,28 @@ import (
"testing"
)
func TestYAMLDecoder(t *testing.T) {
func TestYAMLDecoderReadBytesLength(t *testing.T) {
d := `---
stuff: 1
test-foo: 1
`
s := NewDocumentDecoder(ioutil.NopCloser(bytes.NewReader([]byte(d))))
b := make([]byte, len(d))
n, err := s.Read(b)
if err != nil || n != len(d) {
t.Fatalf("unexpected body: %d / %v", n, err)
testCases := []struct {
bufLen int
expectLen int
expectErr error
}{
{len(d), len(d), nil},
{len(d) + 10, len(d), nil},
{len(d) - 10, len(d) - 10, io.ErrShortBuffer},
}
for i, testCase := range testCases {
r := NewDocumentDecoder(ioutil.NopCloser(bytes.NewReader([]byte(d))))
b := make([]byte, testCase.bufLen)
n, err := r.Read(b)
if err != testCase.expectErr || n != testCase.expectLen {
t.Fatalf("%d: unexpected body: %d / %v", i, n, err)
}
}
}