mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
Extend YAMLDecoder Read tests
This commit is contained in:
parent
86d02ac368
commit
e913612003
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user