mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Fix YAMLDecoder Read behaviour
Make it adhere to the Read contract by returning the number of bytes read.
This commit is contained in:
parent
bb72237375
commit
86d02ac368
@ -122,7 +122,7 @@ func (d *YAMLDecoder) Read(data []byte) (n int, err error) {
|
||||
if left <= len(data) {
|
||||
copy(data, d.remaining)
|
||||
d.remaining = nil
|
||||
return len(d.remaining), nil
|
||||
return left, nil
|
||||
}
|
||||
|
||||
// caller will need to reread
|
||||
|
@ -22,12 +22,26 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestYAMLDecoder(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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitYAMLDocument(t *testing.T) {
|
||||
testCases := []struct {
|
||||
input string
|
||||
|
Loading…
Reference in New Issue
Block a user