This repository has been archived by the owner on Mar 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_resource_test.go
75 lines (62 loc) · 1.87 KB
/
custom_resource_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package kubekit_test
import (
"testing"
"github.com/jelmersnoeck/kubekit"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func TestDefault(t *testing.T) {
t.Run("default name", func(t *testing.T) {
cr := kubekit.CustomResource{Object: &TestType{}}
if name := cr.GetName(); name != "testtype" {
t.Errorf("Expected name to be 'testtype', got '%s'", name)
}
})
t.Run("default plural", func(t *testing.T) {
cr := kubekit.CustomResource{Object: &TestType{}}
if name := cr.GetPlural(); name != "testtypes" {
t.Errorf("Expected name to be 'testtypes', got '%s'", name)
}
})
t.Run("fullname", func(t *testing.T) {
cr := kubekit.CustomResource{Object: &TestType{}, Group: "kubekit"}
if name := cr.FullName(); name != "testtypes.kubekit" {
t.Errorf("Expected name to be 'testtypes.kubekit', got '%s'", name)
}
})
}
func TestGroupVersionKind(t *testing.T) {
tests := []struct {
GVK schema.GroupVersionKind
Resource kubekit.CustomResource
}{
{
schema.GroupVersionKind{Group: "kubekit", Version: "v1test1", Kind: "TestType"},
kubekit.CustomResource{Group: "kubekit", Version: "v1test1", Object: &TestType{}},
},
}
for _, i := range tests {
if i.Resource.GroupVersionKind() != i.GVK {
t.Errorf("GVK does not equal for '%s'", i.Resource.FullName())
}
}
}
type TestType struct{}
func (tt *TestType) DeepCopyObject() runtime.Object { return tt }
func (_ *TestType) GetObjectKind() schema.ObjectKind { return nil }
func TestTypeName(t *testing.T) {
tests := []struct {
Name string
Object interface{}
}{
{"TestType", &TestType{}},
{"TestType", TestType{}},
{"CustomResource", &kubekit.CustomResource{}},
{"CustomResource", kubekit.CustomResource{}},
}
for _, i := range tests {
if name := kubekit.TypeName(i.Object); name != i.Name {
t.Errorf("Expected name to be '%s', got '%s'", i.Name, name)
}
}
}