mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
api and api/v1beta1 pass tests again
This commit is contained in:
parent
77edb91032
commit
828b70abb9
@ -85,7 +85,7 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
func objDiff(a, b interface{}) string {
|
func objDiff(a, b runtime.Object) string {
|
||||||
ab, err := json.Marshal(a)
|
ab, err := json.Marshal(a)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("a")
|
panic("a")
|
||||||
@ -105,7 +105,7 @@ func objDiff(a, b interface{}) string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTest(t *testing.T, source interface{}) {
|
func runTest(t *testing.T, source runtime.Object) {
|
||||||
name := reflect.TypeOf(source).Elem().Name()
|
name := reflect.TypeOf(source).Elem().Name()
|
||||||
apiObjectFuzzer.Fuzz(source)
|
apiObjectFuzzer.Fuzz(source)
|
||||||
j, err := runtime.FindJSONBase(source)
|
j, err := runtime.FindJSONBase(source)
|
||||||
@ -115,13 +115,13 @@ func runTest(t *testing.T, source interface{}) {
|
|||||||
j.SetKind("")
|
j.SetKind("")
|
||||||
j.SetAPIVersion("")
|
j.SetAPIVersion("")
|
||||||
|
|
||||||
data, err := runtime.Encode(source)
|
data, err := runtime.Codec.Encode(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: %v (%#v)", name, err, source)
|
t.Errorf("%v: %v (%#v)", name, err, source)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
obj2, err := runtime.Decode(data)
|
obj2, err := runtime.Codec.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: %v", name, err)
|
t.Errorf("%v: %v", name, err)
|
||||||
return
|
return
|
||||||
@ -131,8 +131,8 @@ func runTest(t *testing.T, source interface{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface()
|
obj3 := reflect.New(reflect.TypeOf(source).Elem()).Interface().(runtime.Object)
|
||||||
err = runtime.DecodeInto(data, obj3)
|
err = runtime.Codec.DecodeInto(data, obj3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("2: %v: %v", name, err)
|
t.Errorf("2: %v: %v", name, err)
|
||||||
return
|
return
|
||||||
@ -145,7 +145,7 @@ func runTest(t *testing.T, source interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTypes(t *testing.T) {
|
func TestTypes(t *testing.T) {
|
||||||
table := []interface{}{
|
table := []runtime.Object{
|
||||||
&api.PodList{},
|
&api.PodList{},
|
||||||
&api.Pod{},
|
&api.Pod{},
|
||||||
&api.ServiceList{},
|
&api.ServiceList{},
|
||||||
@ -169,31 +169,13 @@ func TestTypes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncode_NonPtr(t *testing.T) {
|
|
||||||
pod := api.Pod{
|
|
||||||
Labels: map[string]string{"name": "foo"},
|
|
||||||
}
|
|
||||||
obj := interface{}(pod)
|
|
||||||
data, err := runtime.Encode(obj)
|
|
||||||
obj2, err2 := runtime.Decode(data)
|
|
||||||
if err != nil || err2 != nil {
|
|
||||||
t.Fatalf("Failure: '%v' '%v'", err, err2)
|
|
||||||
}
|
|
||||||
if _, ok := obj2.(*api.Pod); !ok {
|
|
||||||
t.Fatalf("Got wrong type")
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(obj2, &pod) {
|
|
||||||
t.Errorf("Expected:\n %#v,\n Got:\n %#v", &pod, obj2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEncode_Ptr(t *testing.T) {
|
func TestEncode_Ptr(t *testing.T) {
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
Labels: map[string]string{"name": "foo"},
|
Labels: map[string]string{"name": "foo"},
|
||||||
}
|
}
|
||||||
obj := interface{}(pod)
|
obj := runtime.Object(pod)
|
||||||
data, err := runtime.Encode(obj)
|
data, err := runtime.Codec.Encode(obj)
|
||||||
obj2, err2 := runtime.Decode(data)
|
obj2, err2 := runtime.Codec.Decode(data)
|
||||||
if err != nil || err2 != nil {
|
if err != nil || err2 != nil {
|
||||||
t.Fatalf("Failure: '%v' '%v'", err, err2)
|
t.Fatalf("Failure: '%v' '%v'", err, err2)
|
||||||
}
|
}
|
||||||
@ -207,11 +189,11 @@ func TestEncode_Ptr(t *testing.T) {
|
|||||||
|
|
||||||
func TestBadJSONRejection(t *testing.T) {
|
func TestBadJSONRejection(t *testing.T) {
|
||||||
badJSONMissingKind := []byte(`{ }`)
|
badJSONMissingKind := []byte(`{ }`)
|
||||||
if _, err := runtime.Decode(badJSONMissingKind); err == nil {
|
if _, err := runtime.Codec.Decode(badJSONMissingKind); err == nil {
|
||||||
t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind)
|
t.Errorf("Did not reject despite lack of kind field: %s", badJSONMissingKind)
|
||||||
}
|
}
|
||||||
badJSONUnknownType := []byte(`{"kind": "bar"}`)
|
badJSONUnknownType := []byte(`{"kind": "bar"}`)
|
||||||
if _, err1 := runtime.Decode(badJSONUnknownType); err1 == nil {
|
if _, err1 := runtime.Codec.Decode(badJSONUnknownType); err1 == nil {
|
||||||
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
|
t.Errorf("Did not reject despite use of unknown type: %s", badJSONUnknownType)
|
||||||
}
|
}
|
||||||
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
|
/*badJSONKindMismatch := []byte(`{"kind": "Pod"}`)
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Convert = runtime.Convert
|
var Convert = runtime.DefaultScheme.Convert
|
||||||
|
|
||||||
func TestEnvConversion(t *testing.T) {
|
func TestEnvConversion(t *testing.T) {
|
||||||
nonCanonical := []v1beta1.EnvVar{
|
nonCanonical := []v1beta1.EnvVar{
|
||||||
|
Loading…
Reference in New Issue
Block a user