Skip to content

Commit dbde40e

Browse files
selk8s-publishing-bot
authored andcommitted
Fix YAMLDecoder Read behaviour
Make it adhere to the Read contract by returning the number of bytes read. Kubernetes-commit: 86d02ac36811dfadad089f9a5d2ceb95b1288056
1 parent 5250765 commit dbde40e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pkg/util/yaml/decoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (d *YAMLDecoder) Read(data []byte) (n int, err error) {
122122
if left <= len(data) {
123123
copy(data, d.remaining)
124124
d.remaining = nil
125-
return len(d.remaining), nil
125+
return left, nil
126126
}
127127

128128
// caller will need to reread

pkg/util/yaml/decoder_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"io"
25+
"io/ioutil"
2526
"math/rand"
2627
"reflect"
2728
"strings"
2829
"testing"
2930
)
3031

32+
func TestYAMLDecoder(t *testing.T) {
33+
d := `---
34+
stuff: 1
35+
test-foo: 1
36+
`
37+
s := NewDocumentDecoder(ioutil.NopCloser(bytes.NewReader([]byte(d))))
38+
b := make([]byte, len(d))
39+
n, err := s.Read(b)
40+
if err != nil || n != len(d) {
41+
t.Fatalf("unexpected body: %d / %v", n, err)
42+
}
43+
}
44+
3145
func TestSplitYAMLDocument(t *testing.T) {
3246
testCases := []struct {
3347
input string

0 commit comments

Comments
 (0)