func TestUnstructuredSetters(t *testing.T) { unstruct := runtime.Unstructured{} want := runtime.Unstructured{ Object: map[string]interface{}{ "kind": "test_kind", "apiVersion": "test_version", "metadata": map[string]interface{}{ "name": "test_name", "namespace": "test_namespace", "generateName": "test_generateName", "uid": "test_uid", "resourceVersion": "test_resourceVersion", "selfLink": "test_selfLink", "creationTimestamp": "2009-11-10T23:00:00Z", "deletionTimestamp": "2010-11-10T23:00:00Z", "labels": map[string]interface{}{ "test_label": "test_value", }, "annotations": map[string]interface{}{ "test_annotation": "test_value", }, }, }, } unstruct.SetAPIVersion("test_version") unstruct.SetKind("test_kind") unstruct.SetNamespace("test_namespace") unstruct.SetName("test_name") unstruct.SetGenerateName("test_generateName") unstruct.SetUID(types.UID("test_uid")) unstruct.SetResourceVersion("test_resourceVersion") unstruct.SetSelfLink("test_selfLink") unstruct.SetCreationTimestamp(unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) date := unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC) unstruct.SetDeletionTimestamp(&date) unstruct.SetLabels(map[string]string{"test_label": "test_value"}) unstruct.SetAnnotations(map[string]string{"test_annotation": "test_value"}) if !reflect.DeepEqual(unstruct, want) { t.Errorf("Wanted: \n%s\n Got:\n%s", unstruct, want) } }
func TestUnstructuredSetters(t *testing.T) { unstruct := runtime.Unstructured{} trueVar := true want := runtime.Unstructured{ Object: map[string]interface{}{ "kind": "test_kind", "apiVersion": "test_version", "metadata": map[string]interface{}{ "name": "test_name", "namespace": "test_namespace", "generateName": "test_generateName", "uid": "test_uid", "resourceVersion": "test_resourceVersion", "selfLink": "test_selfLink", "creationTimestamp": "2009-11-10T23:00:00Z", "deletionTimestamp": "2010-11-10T23:00:00Z", "labels": map[string]interface{}{ "test_label": "test_value", }, "annotations": map[string]interface{}{ "test_annotation": "test_value", }, "ownerReferences": []map[string]interface{}{ { "kind": "Pod", "name": "poda", "apiVersion": "v1", "uid": "1", "controller": (*bool)(nil), }, { "kind": "Pod", "name": "podb", "apiVersion": "v1", "uid": "2", "controller": &trueVar, }, }, "finalizers": []interface{}{ "finalizer.1", "finalizer.2", }, "clusterName": "cluster123", }, }, } unstruct.SetAPIVersion("test_version") unstruct.SetKind("test_kind") unstruct.SetNamespace("test_namespace") unstruct.SetName("test_name") unstruct.SetGenerateName("test_generateName") unstruct.SetUID(types.UID("test_uid")) unstruct.SetResourceVersion("test_resourceVersion") unstruct.SetSelfLink("test_selfLink") unstruct.SetCreationTimestamp(unversioned.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) date := unversioned.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC) unstruct.SetDeletionTimestamp(&date) unstruct.SetLabels(map[string]string{"test_label": "test_value"}) unstruct.SetAnnotations(map[string]string{"test_annotation": "test_value"}) newOwnerReferences := []metatypes.OwnerReference{ { Kind: "Pod", Name: "poda", APIVersion: "v1", UID: "1", }, { Kind: "Pod", Name: "podb", APIVersion: "v1", UID: "2", Controller: &trueVar, }, } unstruct.SetOwnerReferences(newOwnerReferences) unstruct.SetFinalizers([]string{"finalizer.1", "finalizer.2"}) unstruct.SetClusterName("cluster123") if !reflect.DeepEqual(unstruct, want) { t.Errorf("Wanted: \n%s\n Got:\n%s", want, unstruct) } }