Adding dynamic client
This commit is contained in:
@@ -18,6 +18,7 @@ package runtime_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@@ -46,3 +47,77 @@ func TestDecodeUnstructured(t *testing.T) {
|
||||
t.Errorf("object not converted: %#v", pl.Items[2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
tcs := []struct {
|
||||
json []byte
|
||||
want runtime.Object
|
||||
}{
|
||||
{
|
||||
json: []byte(`{"apiVersion": "test", "kind": "test_kind"}`),
|
||||
want: &runtime.Unstructured{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
APIVersion: "test",
|
||||
Kind: "test_kind",
|
||||
},
|
||||
Object: map[string]interface{}{"apiVersion": "test", "kind": "test_kind"},
|
||||
},
|
||||
},
|
||||
{
|
||||
json: []byte(`{"apiVersion": "test", "kind": "test_list", "items": []}`),
|
||||
want: &runtime.UnstructuredList{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
APIVersion: "test",
|
||||
Kind: "test_list",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
json: []byte(`{"items": [{"metadata": {"name": "object1"}, "apiVersion": "test", "kind": "test_kind"}, {"metadata": {"name": "object2"}, "apiVersion": "test", "kind": "test_kind"}], "apiVersion": "test", "kind": "test_list"}`),
|
||||
want: &runtime.UnstructuredList{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
APIVersion: "test",
|
||||
Kind: "test_list",
|
||||
},
|
||||
Items: []*runtime.Unstructured{
|
||||
{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
APIVersion: "test",
|
||||
Kind: "test_kind",
|
||||
},
|
||||
Name: "object1",
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{"name": "object1"},
|
||||
"apiVersion": "test",
|
||||
"kind": "test_kind",
|
||||
},
|
||||
},
|
||||
{
|
||||
TypeMeta: runtime.TypeMeta{
|
||||
APIVersion: "test",
|
||||
Kind: "test_kind",
|
||||
},
|
||||
Name: "object2",
|
||||
Object: map[string]interface{}{
|
||||
"metadata": map[string]interface{}{"name": "object2"},
|
||||
"apiVersion": "test",
|
||||
"kind": "test_kind",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tcs {
|
||||
got, _, err := runtime.UnstructuredJSONScheme.Decode(tc.json, nil, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error for %q: %v", string(tc.json), err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, tc.want) {
|
||||
t.Errorf("Decode(%q) want: %v\ngot: %v", string(tc.json), tc.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user