mirror of https://github.com/k3s-io/k3s
Use deep spew in serialization test & go obj diff
parent
cee14ab51b
commit
b3304c49ad
|
@ -32,6 +32,7 @@ import (
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
@ -52,20 +53,22 @@ func fuzzInternalObject(t *testing.T, forVersion string, item runtime.Object, se
|
||||||
}
|
}
|
||||||
|
|
||||||
func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
|
func roundTrip(t *testing.T, codec runtime.Codec, item runtime.Object) {
|
||||||
|
printer := spew.ConfigState{DisableMethods: true}
|
||||||
|
|
||||||
name := reflect.TypeOf(item).Elem().Name()
|
name := reflect.TypeOf(item).Elem().Name()
|
||||||
data, err := codec.Encode(item)
|
data, err := codec.Encode(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: %v (%#v)", name, err, item)
|
t.Errorf("%v: %v (%s)", name, err, printer.Sprintf("%#v", item))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
obj2, err := codec.Decode(data)
|
obj2, err := codec.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("0: %v: %v\nCodec: %v\nData: %s\nSource: %#v", name, err, codec, string(data), item)
|
t.Errorf("0: %v: %v\nCodec: %v\nData: %s\nSource: %#v", name, err, codec, string(data), printer.Sprintf("%#v", item))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !api.Semantic.DeepEqual(item, obj2) {
|
if !api.Semantic.DeepEqual(item, obj2) {
|
||||||
t.Errorf("1: %v: diff: %v\nCodec: %v\nData: %s\nSource: %#v\nFinal: %#v", name, util.ObjectGoPrintDiff(item, obj2), codec, string(data), item, obj2)
|
t.Errorf("1: %v: diff: %v\nCodec: %v\nData: %s\nSource: %#v\nFinal: %#v", name, util.ObjectGoPrintDiff(item, obj2), codec, string(data), printer.Sprintf("%#v", item), printer.Sprintf("%#v", obj2))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,10 @@ func ObjectDiff(a, b interface{}) string {
|
||||||
// can't figure out why reflect.DeepEqual is returning false and nothing is
|
// can't figure out why reflect.DeepEqual is returning false and nothing is
|
||||||
// showing you differences. This will.
|
// showing you differences. This will.
|
||||||
func ObjectGoPrintDiff(a, b interface{}) string {
|
func ObjectGoPrintDiff(a, b interface{}) string {
|
||||||
|
s := spew.ConfigState{DisableMethods: true}
|
||||||
return StringDiff(
|
return StringDiff(
|
||||||
spew.Sprintf("%#v", a),
|
s.Sprintf("%#v", a),
|
||||||
spew.Sprintf("%#v", b),
|
s.Sprintf("%#v", b),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue