mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Merge pull request #2756 from liggitt/yaml_bump
Bump yaml, test full int64 serialization
This commit is contained in:
commit
2261c3e71c
2
Godeps/Godeps.json
generated
2
Godeps/Godeps.json
generated
@ -160,7 +160,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "gopkg.in/v2/yaml",
|
"ImportPath": "gopkg.in/v2/yaml",
|
||||||
"Rev": "8fac37523b5c7a1128bf0217f6bd07be1ad266b2"
|
"Rev": "d466437aa4adc35830964cffc5b5f262c63ddcb4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
59
Godeps/_workspace/src/gopkg.in/v2/yaml/decode.go
generated
vendored
59
Godeps/_workspace/src/gopkg.in/v2/yaml/decode.go
generated
vendored
@ -4,8 +4,8 @@ import (
|
|||||||
"encoding"
|
"encoding"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -32,9 +32,9 @@ type node struct {
|
|||||||
// Parser, produces a node tree out of a libyaml event stream.
|
// Parser, produces a node tree out of a libyaml event stream.
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
parser yaml_parser_t
|
parser yaml_parser_t
|
||||||
event yaml_event_t
|
event yaml_event_t
|
||||||
doc *node
|
doc *node
|
||||||
}
|
}
|
||||||
|
|
||||||
func newParser(b []byte) *parser {
|
func newParser(b []byte) *parser {
|
||||||
@ -194,10 +194,10 @@ type decoder struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mapItemType = reflect.TypeOf(MapItem{})
|
mapItemType = reflect.TypeOf(MapItem{})
|
||||||
durationType = reflect.TypeOf(time.Duration(0))
|
durationType = reflect.TypeOf(time.Duration(0))
|
||||||
defaultMapType = reflect.TypeOf(map[interface{}]interface{}{})
|
defaultMapType = reflect.TypeOf(map[interface{}]interface{}{})
|
||||||
ifaceType = defaultMapType.Elem()
|
ifaceType = defaultMapType.Elem()
|
||||||
)
|
)
|
||||||
|
|
||||||
func newDecoder() *decoder {
|
func newDecoder() *decoder {
|
||||||
@ -207,7 +207,6 @@ func newDecoder() *decoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *decoder) terror(n *node, tag string, out reflect.Value) {
|
func (d *decoder) terror(n *node, tag string, out reflect.Value) {
|
||||||
debug.PrintStack()
|
|
||||||
if n.tag != "" {
|
if n.tag != "" {
|
||||||
tag = n.tag
|
tag = n.tag
|
||||||
}
|
}
|
||||||
@ -252,20 +251,13 @@ func (d *decoder) callUnmarshaler(n *node, u Unmarshaler) (good bool) {
|
|||||||
//
|
//
|
||||||
// If n holds a null value, prepare returns before doing anything.
|
// If n holds a null value, prepare returns before doing anything.
|
||||||
func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) {
|
func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) {
|
||||||
//fmt.Printf("yv2 prepare: out.Kind(): %s\n", out.Kind())
|
if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "") {
|
||||||
//fmt.Printf("yv2 prepare: n.tag: %s\n", n.tag)
|
|
||||||
//fmt.Printf("yv2 prepare: n.value: %s\n", n.value)
|
|
||||||
//fmt.Printf("yv2 prepare: n.kind: %s\n", n.kind)
|
|
||||||
if (n.tag == yaml_NULL_TAG) || (n.kind == scalarNode && n.tag == "" && (n.value == "" && n.implicit)) {
|
|
||||||
//fmt.Printf("yv2 prepare: return immediately\n")
|
|
||||||
return out, false, false
|
return out, false, false
|
||||||
}
|
}
|
||||||
//fmt.Printf("yv2 prepare: continue\n")
|
|
||||||
again := true
|
again := true
|
||||||
for again {
|
for again {
|
||||||
again = false
|
again = false
|
||||||
if out.Kind() == reflect.Ptr {
|
if out.Kind() == reflect.Ptr {
|
||||||
//fmt.Printf("yv2 prepare: hit Ptr %s\n", out.Kind())
|
|
||||||
if out.IsNil() {
|
if out.IsNil() {
|
||||||
out.Set(reflect.New(out.Type().Elem()))
|
out.Set(reflect.New(out.Type().Elem()))
|
||||||
}
|
}
|
||||||
@ -338,18 +330,12 @@ func resetMap(out reflect.Value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
||||||
//fmt.Printf("yv2 1 tag: %s, implicit: %v, out.Type(): %s\n", n.tag, n.implicit, out.Type())
|
|
||||||
//fmt.Printf("yv2 n.value: %v\n", n.value)
|
|
||||||
//fmt.Printf("yv2 n.kind: %v\n", n.kind)
|
|
||||||
//fmt.Printf("yv2 n.tag: %v\n", n.tag)
|
|
||||||
var tag string
|
var tag string
|
||||||
var resolved interface{}
|
var resolved interface{}
|
||||||
if n.tag == "" && !n.implicit {
|
if n.tag == "" && !n.implicit {
|
||||||
//fmt.Printf("yv2 2\n")
|
|
||||||
tag = yaml_STR_TAG
|
tag = yaml_STR_TAG
|
||||||
resolved = n.value
|
resolved = n.value
|
||||||
} else {
|
} else {
|
||||||
//fmt.Printf("yv2 3\n")
|
|
||||||
tag, resolved = resolve(n.tag, n.value)
|
tag, resolved = resolve(n.tag, n.value)
|
||||||
if tag == yaml_BINARY_TAG {
|
if tag == yaml_BINARY_TAG {
|
||||||
data, err := base64.StdEncoding.DecodeString(resolved.(string))
|
data, err := base64.StdEncoding.DecodeString(resolved.(string))
|
||||||
@ -359,9 +345,7 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
resolved = string(data)
|
resolved = string(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fmt.Printf("yv2 4\n")
|
|
||||||
if resolved == nil {
|
if resolved == nil {
|
||||||
//fmt.Printf("yv2 5\n")
|
|
||||||
if out.Kind() == reflect.Map && !out.CanAddr() {
|
if out.Kind() == reflect.Map && !out.CanAddr() {
|
||||||
resetMap(out)
|
resetMap(out)
|
||||||
} else {
|
} else {
|
||||||
@ -370,7 +354,6 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if s, ok := resolved.(string); ok && out.CanAddr() {
|
if s, ok := resolved.(string); ok && out.CanAddr() {
|
||||||
//fmt.Printf("yv2 6")
|
|
||||||
if u, ok := out.Addr().Interface().(encoding.TextUnmarshaler); ok {
|
if u, ok := out.Addr().Interface().(encoding.TextUnmarshaler); ok {
|
||||||
err := u.UnmarshalText([]byte(s))
|
err := u.UnmarshalText([]byte(s))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -379,9 +362,6 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fmt.Printf("yv2 resolved tag: %v\n", tag)
|
|
||||||
//fmt.Printf("yv2 resolved: %v\n", resolved)
|
|
||||||
//fmt.Printf("yv2 resolved type: %v\n", reflect.TypeOf(resolved))
|
|
||||||
switch out.Kind() {
|
switch out.Kind() {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
if tag == yaml_BINARY_TAG {
|
if tag == yaml_BINARY_TAG {
|
||||||
@ -410,8 +390,13 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
out.SetInt(resolved)
|
out.SetInt(resolved)
|
||||||
good = true
|
good = true
|
||||||
}
|
}
|
||||||
|
case uint64:
|
||||||
|
if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) {
|
||||||
|
out.SetInt(int64(resolved))
|
||||||
|
good = true
|
||||||
|
}
|
||||||
case float64:
|
case float64:
|
||||||
if resolved < 1<<63-1 && !out.OverflowInt(int64(resolved)) {
|
if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) {
|
||||||
out.SetInt(int64(resolved))
|
out.SetInt(int64(resolved))
|
||||||
good = true
|
good = true
|
||||||
}
|
}
|
||||||
@ -427,17 +412,22 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||||
switch resolved := resolved.(type) {
|
switch resolved := resolved.(type) {
|
||||||
case int:
|
case int:
|
||||||
if resolved >= 0 {
|
if resolved >= 0 && !out.OverflowUint(uint64(resolved)) {
|
||||||
out.SetUint(uint64(resolved))
|
out.SetUint(uint64(resolved))
|
||||||
good = true
|
good = true
|
||||||
}
|
}
|
||||||
case int64:
|
case int64:
|
||||||
if resolved >= 0 {
|
if resolved >= 0 && !out.OverflowUint(uint64(resolved)) {
|
||||||
|
out.SetUint(uint64(resolved))
|
||||||
|
good = true
|
||||||
|
}
|
||||||
|
case uint64:
|
||||||
|
if !out.OverflowUint(uint64(resolved)) {
|
||||||
out.SetUint(uint64(resolved))
|
out.SetUint(uint64(resolved))
|
||||||
good = true
|
good = true
|
||||||
}
|
}
|
||||||
case float64:
|
case float64:
|
||||||
if resolved < 1<<64-1 && !out.OverflowUint(uint64(resolved)) {
|
if resolved <= math.MaxUint64 && !out.OverflowUint(uint64(resolved)) {
|
||||||
out.SetUint(uint64(resolved))
|
out.SetUint(uint64(resolved))
|
||||||
good = true
|
good = true
|
||||||
}
|
}
|
||||||
@ -456,6 +446,9 @@ func (d *decoder) scalar(n *node, out reflect.Value) (good bool) {
|
|||||||
case int64:
|
case int64:
|
||||||
out.SetFloat(float64(resolved))
|
out.SetFloat(float64(resolved))
|
||||||
good = true
|
good = true
|
||||||
|
case uint64:
|
||||||
|
out.SetFloat(float64(resolved))
|
||||||
|
good = true
|
||||||
case float64:
|
case float64:
|
||||||
out.SetFloat(resolved)
|
out.SetFloat(resolved)
|
||||||
good = true
|
good = true
|
||||||
@ -510,6 +503,8 @@ func (d *decoder) sequence(n *node, out reflect.Value) (good bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (d *decoder) mapping(n *node, out reflect.Value) (good bool) {
|
func (d *decoder) mapping(n *node, out reflect.Value) (good bool) {
|
||||||
switch out.Kind() {
|
switch out.Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
|
178
Godeps/_workspace/src/gopkg.in/v2/yaml/decode_test.go
generated
vendored
178
Godeps/_workspace/src/gopkg.in/v2/yaml/decode_test.go
generated
vendored
@ -2,16 +2,13 @@ package yaml_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
. "gopkg.in/check.v1"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
. "gopkg.in/check.v1"
|
|
||||||
"gopkg.in/v2/yaml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var unmarshalIntTest = 123
|
var unmarshalIntTest = 123
|
||||||
@ -270,6 +267,114 @@ var unmarshalTests = []struct {
|
|||||||
map[string]uint64{},
|
map[string]uint64{},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// int
|
||||||
|
{
|
||||||
|
"int_max: 2147483647",
|
||||||
|
map[string]int{"int_max": math.MaxInt32},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int_min: -2147483648",
|
||||||
|
map[string]int{"int_min": math.MinInt32},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int_overflow: 9223372036854775808", // math.MaxInt64 + 1
|
||||||
|
map[string]int{},
|
||||||
|
},
|
||||||
|
|
||||||
|
// int64
|
||||||
|
{
|
||||||
|
"int64_max: 9223372036854775807",
|
||||||
|
map[string]int64{"int64_max": math.MaxInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int64_max_base2: 0b111111111111111111111111111111111111111111111111111111111111111",
|
||||||
|
map[string]int64{"int64_max_base2": math.MaxInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int64_min: -9223372036854775808",
|
||||||
|
map[string]int64{"int64_min": math.MinInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int64_neg_base2: -0b111111111111111111111111111111111111111111111111111111111111111",
|
||||||
|
map[string]int64{"int64_neg_base2": -math.MaxInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"int64_overflow: 9223372036854775808", // math.MaxInt64 + 1
|
||||||
|
map[string]int64{},
|
||||||
|
},
|
||||||
|
|
||||||
|
// uint
|
||||||
|
{
|
||||||
|
"uint_min: 0",
|
||||||
|
map[string]uint{"uint_min": 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint_max: 4294967295",
|
||||||
|
map[string]uint{"uint_max": math.MaxUint32},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint_underflow: -1",
|
||||||
|
map[string]uint{},
|
||||||
|
},
|
||||||
|
|
||||||
|
// uint64
|
||||||
|
{
|
||||||
|
"uint64_min: 0",
|
||||||
|
map[string]uint{"uint64_min": 0},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint64_max: 18446744073709551615",
|
||||||
|
map[string]uint64{"uint64_max": math.MaxUint64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint64_max_base2: 0b1111111111111111111111111111111111111111111111111111111111111111",
|
||||||
|
map[string]uint64{"uint64_max_base2": math.MaxUint64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint64_maxint64: 9223372036854775807",
|
||||||
|
map[string]uint64{"uint64_maxint64": math.MaxInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uint64_underflow: -1",
|
||||||
|
map[string]uint64{},
|
||||||
|
},
|
||||||
|
|
||||||
|
// float32
|
||||||
|
{
|
||||||
|
"float32_max: 3.40282346638528859811704183484516925440e+38",
|
||||||
|
map[string]float32{"float32_max": math.MaxFloat32},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float32_nonzero: 1.401298464324817070923729583289916131280e-45",
|
||||||
|
map[string]float32{"float32_nonzero": math.SmallestNonzeroFloat32},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float32_maxuint64: 18446744073709551615",
|
||||||
|
map[string]float32{"float32_maxuint64": float32(math.MaxUint64)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float32_maxuint64+1: 18446744073709551616",
|
||||||
|
map[string]float32{"float32_maxuint64+1": float32(math.MaxUint64 + 1)},
|
||||||
|
},
|
||||||
|
|
||||||
|
// float64
|
||||||
|
{
|
||||||
|
"float64_max: 1.797693134862315708145274237317043567981e+308",
|
||||||
|
map[string]float64{"float64_max": math.MaxFloat64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float64_nonzero: 4.940656458412465441765687928682213723651e-324",
|
||||||
|
map[string]float64{"float64_nonzero": math.SmallestNonzeroFloat64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float64_maxuint64: 18446744073709551615",
|
||||||
|
map[string]float64{"float64_maxuint64": float64(math.MaxUint64)},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"float64_maxuint64+1: 18446744073709551616",
|
||||||
|
map[string]float64{"float64_maxuint64+1": float64(math.MaxUint64 + 1)},
|
||||||
|
},
|
||||||
|
|
||||||
// Overflow cases.
|
// Overflow cases.
|
||||||
{
|
{
|
||||||
"v: 4294967297",
|
"v: 4294967297",
|
||||||
@ -462,13 +567,7 @@ func (s *S) TestUnmarshal(c *C) {
|
|||||||
if t.Kind() == reflect.String {
|
if t.Kind() == reflect.String {
|
||||||
c.Assert(*value.(*string), Equals, item.value)
|
c.Assert(*value.(*string), Equals, item.value)
|
||||||
} else {
|
} else {
|
||||||
if !c.Check(value, DeepEquals, item.value) {
|
c.Assert(value, DeepEquals, item.value)
|
||||||
fmt.Printf("Spew:\n")
|
|
||||||
spew.Dump(item.data)
|
|
||||||
spew.Dump(item.value)
|
|
||||||
spew.Dump(value)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -773,61 +872,6 @@ func (s *S) TestUnmarshalNull(c *C) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringStructContainer struct {
|
|
||||||
Val StringStruct
|
|
||||||
}
|
|
||||||
|
|
||||||
type StringStruct struct {
|
|
||||||
StrVal string
|
|
||||||
UnmarshalCalled bool // to be able to check that UnmarshalYAML was actually called
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
||||||
func (s *StringStruct) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
||||||
var value *string
|
|
||||||
if err := unmarshal(&value); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
s.StrVal = *value
|
|
||||||
s.UnmarshalCalled = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a node value is a literal empty string (i.e.: "") but the corresponding
|
|
||||||
// object to Unmarshal to is a struct or a pointer to a struct, the struct must
|
|
||||||
// have UnmarshalYAML() called on it with an empty string.
|
|
||||||
func (s *S) TestUnmarshalEmptyStringToStruct(c *C) {
|
|
||||||
//j := []byte(`{"val": "null"}`)
|
|
||||||
// Literal empty string should call UnmarshalYAML.
|
|
||||||
j := []byte("val: \"\"\n")
|
|
||||||
v := new(StringStructContainer)
|
|
||||||
err := yaml.Unmarshal(j, v)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Assert(v.Val.StrVal, Equals, "")
|
|
||||||
c.Assert(v.Val.UnmarshalCalled, Equals, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *S) TestUnmarshalNullStringToStruct(c *C) {
|
|
||||||
// "null" string should not call UnmarshalYAML, but instead produce a zero object.
|
|
||||||
j := []byte("val: null\n")
|
|
||||||
v := new(StringStructContainer)
|
|
||||||
err := yaml.Unmarshal(j, v)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Assert(v.Val.StrVal, Equals, "")
|
|
||||||
c.Assert(v.Val.UnmarshalCalled, Equals, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Implicit" document ending should not call UnmarshalYAML, but instead produce a blank object.
|
|
||||||
func (s *S) TestUnmarshalImplicitEndingToStruct(c *C) {
|
|
||||||
// "null" string should not call UnmarshalYAML, but instead produce a zero object.
|
|
||||||
j := []byte("val: \n")
|
|
||||||
v := new(StringStructContainer)
|
|
||||||
err := yaml.Unmarshal(j, v)
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
c.Assert(v.Val.StrVal, Equals, "")
|
|
||||||
c.Assert(v.Val.UnmarshalCalled, Equals, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
//var data []byte
|
//var data []byte
|
||||||
//func init() {
|
//func init() {
|
||||||
// var err error
|
// var err error
|
||||||
|
20
Godeps/_workspace/src/gopkg.in/v2/yaml/encode.go
generated
vendored
20
Godeps/_workspace/src/gopkg.in/v2/yaml/encode.go
generated
vendored
@ -63,11 +63,8 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
|
|||||||
e.nilv()
|
e.nilv()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//fmt.Printf("marshal 1 in: %s\n", in)
|
|
||||||
iface := in.Interface()
|
iface := in.Interface()
|
||||||
//fmt.Printf("marshal 1 iface: %s\n", iface)
|
|
||||||
if m, ok := iface.(Marshaler); ok {
|
if m, ok := iface.(Marshaler); ok {
|
||||||
//fmt.Printf("marshal 1 calling MarshalYAML\n")
|
|
||||||
v, err := m.MarshalYAML()
|
v, err := m.MarshalYAML()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail(err)
|
fail(err)
|
||||||
@ -77,20 +74,16 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
in = reflect.ValueOf(v)
|
in = reflect.ValueOf(v)
|
||||||
} else if m, ok := iface.(encoding.TextMarshaler); ok {
|
}
|
||||||
|
if m, ok := iface.(encoding.TextMarshaler); ok {
|
||||||
text, err := m.MarshalText()
|
text, err := m.MarshalText()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail(err)
|
fail(err)
|
||||||
}
|
}
|
||||||
in = reflect.ValueOf(string(text))
|
in = reflect.ValueOf(string(text))
|
||||||
}
|
}
|
||||||
//fmt.Printf("marshal 2 in: %s\n", in)
|
|
||||||
//fmt.Printf("marshal 2 in string: %s\n", in.String())
|
|
||||||
//fmt.Printf("marshal 2 in Kind: %s\n", in.Kind())
|
|
||||||
//fmt.Printf("marshal 2.5 in Kind: %s\n", in.Kind())
|
|
||||||
switch in.Kind() {
|
switch in.Kind() {
|
||||||
case reflect.Interface:
|
case reflect.Interface:
|
||||||
//fmt.Printf("marshal 3\n")
|
|
||||||
if in.IsNil() {
|
if in.IsNil() {
|
||||||
e.nilv()
|
e.nilv()
|
||||||
} else {
|
} else {
|
||||||
@ -99,14 +92,12 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
|
|||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
e.mapv(tag, in)
|
e.mapv(tag, in)
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
//fmt.Printf("marshal 4\n")
|
|
||||||
if in.IsNil() {
|
if in.IsNil() {
|
||||||
e.nilv()
|
e.nilv()
|
||||||
} else {
|
} else {
|
||||||
e.marshal(tag, in.Elem())
|
e.marshal(tag, in.Elem())
|
||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
//fmt.Printf("marshal 5\n")
|
|
||||||
e.structv(tag, in)
|
e.structv(tag, in)
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if in.Type().Elem() == mapItemType {
|
if in.Type().Elem() == mapItemType {
|
||||||
@ -115,7 +106,6 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
|
|||||||
e.slicev(tag, in)
|
e.slicev(tag, in)
|
||||||
}
|
}
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
//fmt.Printf("marshal 6 in.String: \n", in.String())
|
|
||||||
e.stringv(tag, in)
|
e.stringv(tag, in)
|
||||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||||
if in.Type() == durationType {
|
if in.Type() == durationType {
|
||||||
@ -173,7 +163,6 @@ func (e *encoder) structv(tag string, in reflect.Value) {
|
|||||||
}
|
}
|
||||||
e.marshal("", reflect.ValueOf(info.Key))
|
e.marshal("", reflect.ValueOf(info.Key))
|
||||||
e.flow = info.Flow
|
e.flow = info.Flow
|
||||||
//fmt.Printf("structv mappingv value: %s\n", value)
|
|
||||||
e.marshal("", value)
|
e.marshal("", value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -233,17 +222,13 @@ func isBase60Float(s string) (result bool) {
|
|||||||
var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0-9_]*)?$`)
|
var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0-9_]*)?$`)
|
||||||
|
|
||||||
func (e *encoder) stringv(tag string, in reflect.Value) {
|
func (e *encoder) stringv(tag string, in reflect.Value) {
|
||||||
//fmt.Printf("stringv 1\n")
|
|
||||||
var style yaml_scalar_style_t
|
var style yaml_scalar_style_t
|
||||||
s := in.String()
|
s := in.String()
|
||||||
//fmt.Printf("stringv 1 s: %s\n", s)
|
|
||||||
rtag, rs := resolve("", s)
|
rtag, rs := resolve("", s)
|
||||||
if rtag == yaml_BINARY_TAG {
|
if rtag == yaml_BINARY_TAG {
|
||||||
//fmt.Printf("stringv 2\n")
|
|
||||||
if tag == "" || tag == yaml_STR_TAG {
|
if tag == "" || tag == yaml_STR_TAG {
|
||||||
tag = rtag
|
tag = rtag
|
||||||
s = rs.(string)
|
s = rs.(string)
|
||||||
//fmt.Printf("stringv 3 s: %s\n", s)
|
|
||||||
} else if tag == yaml_BINARY_TAG {
|
} else if tag == yaml_BINARY_TAG {
|
||||||
failf("explicitly tagged !!binary data must be base64-encoded")
|
failf("explicitly tagged !!binary data must be base64-encoded")
|
||||||
} else {
|
} else {
|
||||||
@ -257,7 +242,6 @@ func (e *encoder) stringv(tag string, in reflect.Value) {
|
|||||||
} else {
|
} else {
|
||||||
style = yaml_PLAIN_SCALAR_STYLE
|
style = yaml_PLAIN_SCALAR_STYLE
|
||||||
}
|
}
|
||||||
//fmt.Printf("stringv 4 style: %s\n", style)
|
|
||||||
e.emitScalar(s, "", tag, style)
|
e.emitScalar(s, "", tag, style)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
Godeps/_workspace/src/gopkg.in/v2/yaml/resolve.go
generated
vendored
21
Godeps/_workspace/src/gopkg.in/v2/yaml/resolve.go
generated
vendored
@ -81,7 +81,6 @@ func resolvableTag(tag string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolve(tag string, in string) (rtag string, out interface{}) {
|
func resolve(tag string, in string) (rtag string, out interface{}) {
|
||||||
//fmt.Printf("yv2 resolve tag: %s, in: %s\n", tag, in)
|
|
||||||
if !resolvableTag(tag) {
|
if !resolvableTag(tag) {
|
||||||
return tag, in
|
return tag, in
|
||||||
}
|
}
|
||||||
@ -132,6 +131,10 @@ func resolve(tag string, in string) (rtag string, out interface{}) {
|
|||||||
return yaml_INT_TAG, intv
|
return yaml_INT_TAG, intv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uintv, err := strconv.ParseUint(plain, 0, 64)
|
||||||
|
if err == nil {
|
||||||
|
return yaml_INT_TAG, uintv
|
||||||
|
}
|
||||||
floatv, err := strconv.ParseFloat(plain, 64)
|
floatv, err := strconv.ParseFloat(plain, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return yaml_FLOAT_TAG, floatv
|
return yaml_FLOAT_TAG, floatv
|
||||||
@ -139,12 +142,24 @@ func resolve(tag string, in string) (rtag string, out interface{}) {
|
|||||||
if strings.HasPrefix(plain, "0b") {
|
if strings.HasPrefix(plain, "0b") {
|
||||||
intv, err := strconv.ParseInt(plain[2:], 2, 64)
|
intv, err := strconv.ParseInt(plain[2:], 2, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return yaml_INT_TAG, int(intv)
|
if intv == int64(int(intv)) {
|
||||||
|
return yaml_INT_TAG, int(intv)
|
||||||
|
} else {
|
||||||
|
return yaml_INT_TAG, intv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uintv, err := strconv.ParseUint(plain[2:], 2, 64)
|
||||||
|
if err == nil {
|
||||||
|
return yaml_INT_TAG, uintv
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(plain, "-0b") {
|
} else if strings.HasPrefix(plain, "-0b") {
|
||||||
intv, err := strconv.ParseInt(plain[3:], 2, 64)
|
intv, err := strconv.ParseInt(plain[3:], 2, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return yaml_INT_TAG, -int(intv)
|
if intv == int64(int(intv)) {
|
||||||
|
return yaml_INT_TAG, -int(intv)
|
||||||
|
} else {
|
||||||
|
return yaml_INT_TAG, -intv
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XXX Handle timestamps here.
|
// XXX Handle timestamps here.
|
||||||
|
@ -40,10 +40,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
},
|
},
|
||||||
func(j *internal.ObjectMeta, c fuzz.Continue) {
|
func(j *internal.ObjectMeta, c fuzz.Continue) {
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
|
|
||||||
var sec, nsec int64
|
var sec, nsec int64
|
||||||
@ -52,10 +49,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
||||||
},
|
},
|
||||||
func(j *internal.ListMeta, c fuzz.Continue) {
|
func(j *internal.ListMeta, c fuzz.Continue) {
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
},
|
},
|
||||||
func(j *internal.ObjectReference, c fuzz.Continue) {
|
func(j *internal.ObjectReference, c fuzz.Continue) {
|
||||||
@ -65,10 +59,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.Kind = c.RandString()
|
j.Kind = c.RandString()
|
||||||
j.Namespace = c.RandString()
|
j.Namespace = c.RandString()
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.FieldPath = c.RandString()
|
j.FieldPath = c.RandString()
|
||||||
},
|
},
|
||||||
func(j *internal.PodPhase, c fuzz.Continue) {
|
func(j *internal.PodPhase, c fuzz.Continue) {
|
||||||
@ -104,10 +95,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
intstr.StrVal = c.RandString()
|
intstr.StrVal = c.RandString()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(u64 *uint64, c fuzz.Continue) {
|
|
||||||
// TODO: uint64's are NOT handled right.
|
|
||||||
*u64 = c.RandUint64() >> 8
|
|
||||||
},
|
|
||||||
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
||||||
// This is necessary because keys with nil values get omitted.
|
// This is necessary because keys with nil values get omitted.
|
||||||
// TODO: Is this a bug?
|
// TODO: Is this a bug?
|
||||||
|
@ -50,10 +50,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.Kind = ""
|
j.Kind = ""
|
||||||
|
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
|
|
||||||
var sec, nsec int64
|
var sec, nsec int64
|
||||||
@ -69,10 +66,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
},
|
},
|
||||||
func(j *api.ObjectMeta, c fuzz.Continue) {
|
func(j *api.ObjectMeta, c fuzz.Continue) {
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
|
|
||||||
var sec, nsec int64
|
var sec, nsec int64
|
||||||
@ -81,10 +75,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
||||||
},
|
},
|
||||||
func(j *api.ListMeta, c fuzz.Continue) {
|
func(j *api.ListMeta, c fuzz.Continue) {
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
},
|
},
|
||||||
func(j *api.PodPhase, c fuzz.Continue) {
|
func(j *api.PodPhase, c fuzz.Continue) {
|
||||||
@ -120,10 +111,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
intstr.StrVal = c.RandString()
|
intstr.StrVal = c.RandString()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(u64 *uint64, c fuzz.Continue) {
|
|
||||||
// TODO: uint64's are NOT handled right.
|
|
||||||
*u64 = c.RandUint64() >> 8
|
|
||||||
},
|
|
||||||
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
||||||
// This is necessary because keys with nil values get omitted.
|
// This is necessary because keys with nil values get omitted.
|
||||||
// TODO: Is this a bug?
|
// TODO: Is this a bug?
|
||||||
|
@ -51,10 +51,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.Kind = ""
|
j.Kind = ""
|
||||||
|
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
|
|
||||||
var sec, nsec int64
|
var sec, nsec int64
|
||||||
@ -70,10 +67,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
},
|
},
|
||||||
func(j *api.ObjectMeta, c fuzz.Continue) {
|
func(j *api.ObjectMeta, c fuzz.Continue) {
|
||||||
j.Name = c.RandString()
|
j.Name = c.RandString()
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
|
|
||||||
var sec, nsec int64
|
var sec, nsec int64
|
||||||
@ -82,10 +76,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
|
||||||
},
|
},
|
||||||
func(j *api.ListMeta, c fuzz.Continue) {
|
func(j *api.ListMeta, c fuzz.Continue) {
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
j.ResourceVersion = strconv.FormatUint(c.RandUint64(), 10)
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
j.ResourceVersion = strconv.FormatUint(c.RandUint64()>>8, 10)
|
|
||||||
j.SelfLink = c.RandString()
|
j.SelfLink = c.RandString()
|
||||||
},
|
},
|
||||||
func(j *api.PodPhase, c fuzz.Continue) {
|
func(j *api.PodPhase, c fuzz.Continue) {
|
||||||
@ -121,10 +112,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
intstr.StrVal = c.RandString()
|
intstr.StrVal = c.RandString()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(u64 *uint64, c fuzz.Continue) {
|
|
||||||
// TODO: uint64's are NOT handled right.
|
|
||||||
*u64 = c.RandUint64() >> 8
|
|
||||||
},
|
|
||||||
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
func(pb map[docker.Port][]docker.PortBinding, c fuzz.Continue) {
|
||||||
// This is necessary because keys with nil values get omitted.
|
// This is necessary because keys with nil values get omitted.
|
||||||
// TODO: Is this a bug?
|
// TODO: Is this a bug?
|
||||||
|
@ -104,18 +104,6 @@ var TestObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 100).Funcs(
|
|||||||
j.ObjectKind = ""
|
j.ObjectKind = ""
|
||||||
j.ID = c.RandString()
|
j.ID = c.RandString()
|
||||||
},
|
},
|
||||||
func(u *uint64, c fuzz.Continue) {
|
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
*u = c.RandUint64() >> 8
|
|
||||||
},
|
|
||||||
func(u *uint, c fuzz.Continue) {
|
|
||||||
// TODO: Fix JSON/YAML packages and/or write custom encoding
|
|
||||||
// for uint64's. Somehow the LS *byte* of this is lost, but
|
|
||||||
// only when all 8 bytes are set.
|
|
||||||
*u = uint(c.RandUint64() >> 8)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Returns a new Scheme set up with the test objects.
|
// Returns a new Scheme set up with the test objects.
|
||||||
|
Loading…
Reference in New Issue
Block a user