Add TypeAccessor to api/meta for objects without Object/ListMeta

Adding objects that have TypeMeta (use runtime.Scheme) but do not
expose ObjectMeta/ListMeta (because they are not Kube API objects)
and wanted to get the simpler access path for in memory objects.
This commit is contained in:
Clayton Coleman
2015-01-18 21:22:55 -05:00
parent eeb712d163
commit 5f6caaba2e
5 changed files with 62 additions and 6 deletions

View File

@@ -79,6 +79,17 @@ func TestGenericTypeMeta(t *testing.T) {
t.Errorf("expected %v, got %v", e, a)
}
typeAccessor, err := TypeAccessor(&j)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if e, a := "a", accessor.APIVersion(); e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "b", accessor.Kind(); e != a {
t.Errorf("expected %v, got %v", e, a)
}
accessor.SetNamespace("baz")
accessor.SetName("bar")
accessor.SetUID("other")
@@ -109,6 +120,15 @@ func TestGenericTypeMeta(t *testing.T) {
if e, a := "google.com", j.SelfLink; e != a {
t.Errorf("expected %v, got %v", e, a)
}
typeAccessor.SetAPIVersion("d")
typeAccessor.SetKind("e")
if e, a := "d", j.APIVersion; e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "e", j.Kind; e != a {
t.Errorf("expected %v, got %v", e, a)
}
}
type InternalTypeMeta struct {