mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +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) {
|
if left <= len(data) {
|
||||||
copy(data, d.remaining)
|
copy(data, d.remaining)
|
||||||
d.remaining = nil
|
d.remaining = nil
|
||||||
return len(d.remaining), nil
|
return left, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// caller will need to reread
|
// caller will need to reread
|
||||||
|
@ -22,12 +22,26 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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) {
|
func TestSplitYAMLDocument(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
input string
|
input string
|
||||||
|
Loading…
Reference in New Issue
Block a user