Add UID to MetaAccessor and Ref

This commit is contained in:
Clayton Coleman
2014-10-22 22:59:15 -04:00
parent 1ccb86c760
commit 35eaf90255
6 changed files with 32 additions and 5 deletions

View File

@@ -108,6 +108,8 @@ func NewSelfLinker() runtime.SelfLinker {
type Accessor interface {
Name() string
SetName(name string)
UID() string
SetUID(uid string)
APIVersion() string
SetAPIVersion(version string)
Kind() string
@@ -120,6 +122,7 @@ type Accessor interface {
type genericTypeMeta struct {
name *string
uid *string
apiVersion *string
kind *string
resourceVersion *string
@@ -134,6 +137,14 @@ func (g genericTypeMeta) SetName(name string) {
*g.name = name
}
func (g genericTypeMeta) UID() string {
return *g.uid
}
func (g genericTypeMeta) SetUID(uid string) {
*g.uid = uid
}
func (g genericTypeMeta) APIVersion() string {
return *g.apiVersion
}
@@ -199,6 +210,9 @@ func newGenericTypeMeta(v reflect.Value) (genericTypeMeta, error) {
if err := fieldPtr(v, "Name", &g.name); err != nil {
return g, err
}
if err := fieldPtr(v, "UID", &g.uid); err != nil {
return g, err
}
if err := fieldPtr(v, "APIVersion", &g.apiVersion); err != nil {
return g, err
}

View File

@@ -28,6 +28,7 @@ func TestGenericTypeMeta(t *testing.T) {
type TypeMeta struct {
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
UID string `json:"uid,omitempty" yaml:"uid,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty" yaml:"creationTimestamp,omitempty"`
SelfLink string `json:"selfLink,omitempty" yaml:"selfLink,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty" yaml:"resourceVersion,omitempty"`
@@ -35,6 +36,7 @@ func TestGenericTypeMeta(t *testing.T) {
}
j := TypeMeta{
Name: "foo",
UID: "uid",
APIVersion: "a",
Kind: "b",
ResourceVersion: "1",
@@ -49,6 +51,9 @@ func TestGenericTypeMeta(t *testing.T) {
if e, a := "foo", jbi.Name(); e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "uid", jbi.UID(); e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "a", jbi.APIVersion(); e != a {
t.Errorf("expected %v, got %v", e, a)
}
@@ -63,6 +68,7 @@ func TestGenericTypeMeta(t *testing.T) {
}
jbi.SetName("bar")
jbi.SetUID("other")
jbi.SetAPIVersion("c")
jbi.SetKind("d")
jbi.SetResourceVersion("2")
@@ -72,6 +78,9 @@ func TestGenericTypeMeta(t *testing.T) {
if e, a := "bar", j.Name; e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "other", j.UID; e != a {
t.Errorf("expected %v, got %v", e, a)
}
if e, a := "c", j.APIVersion; e != a {
t.Errorf("expected %v, got %v", e, a)
}