vendor updates

This commit is contained in:
Serguei Bezverkhi
2018-03-06 17:33:18 -05:00
parent 4b3ebc171b
commit e9033989a0
5854 changed files with 248382 additions and 119809 deletions

View File

@ -9,8 +9,7 @@ load(
go_test(
name = "go_default_test",
srcs = ["decoder_test.go"],
importpath = "k8s.io/apimachinery/pkg/util/yaml",
library = ":go_default_library",
embed = [":go_default_library"],
)
go_library(

View File

@ -122,12 +122,12 @@ 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
copy(data, d.remaining[:left])
d.remaining = d.remaining[left:]
copy(data, d.remaining[:len(data)])
d.remaining = d.remaining[len(data):]
return len(data), io.ErrShortBuffer
}

View File

@ -22,12 +22,68 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"reflect"
"strings"
"testing"
)
func TestYAMLDecoderReadBytesLength(t *testing.T) {
d := `---
stuff: 1
test-foo: 1
`
testCases := []struct {
bufLen int
expectLen int
expectErr error
}{
{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)
}
}
}
func TestYAMLDecoderCallsAfterErrShortBufferRestOfFrame(t *testing.T) {
d := `---
stuff: 1
test-foo: 1`
r := NewDocumentDecoder(ioutil.NopCloser(bytes.NewReader([]byte(d))))
b := make([]byte, 12)
n, err := r.Read(b)
if err != io.ErrShortBuffer || n != 12 {
t.Fatalf("expected ErrShortBuffer: %d / %v", n, err)
}
expected := "---\nstuff: 1"
if string(b) != expected {
t.Fatalf("expected bytes read to be: %s got: %s", expected, string(b))
}
b = make([]byte, 13)
n, err = r.Read(b)
if err != nil || n != 13 {
t.Fatalf("expected nil: %d / %v", n, err)
}
expected = "\n\ttest-foo: 1"
if string(b) != expected {
t.Fatalf("expected bytes read to be: '%s' got: '%s'", expected, string(b))
}
b = make([]byte, 15)
n, err = r.Read(b)
if err != io.EOF || n != 0 {
t.Fatalf("expected EOF: %d / %v", n, err)
}
}
func TestSplitYAMLDocument(t *testing.T) {
testCases := []struct {
input string