Extend YAMLDecoder Read tests

This commit is contained in:
Steve Larkin 2017-12-12 19:11:23 +01:00
parent 86d02ac368
commit e913612003

View File

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