forked from kubernetes-sigs/controller-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheme_test.go
111 lines (89 loc) · 4.66 KB
/
scheme_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package scheme_test
import (
"reflect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
)
var _ = Describe("Scheme", func() {
Describe("Builder", func() {
It("should provide a Scheme with the types registered", func() {
gv := schema.GroupVersion{Group: "core", Version: "v1"}
s, err := (&scheme.Builder{GroupVersion: gv}).
Register(&corev1.Pod{}, &corev1.PodList{}).
Build()
Expect(err).NotTo(HaveOccurred())
Expect(s.AllKnownTypes()).To(HaveLen(15))
Expect(s.AllKnownTypes()[gv.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{})))
Expect(s.AllKnownTypes()[gv.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{})))
// Base types
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("DeleteOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ExportOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("GetOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ListOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("WatchEvent")))
internalGv := schema.GroupVersion{Group: "core", Version: "__internal"}
Expect(s.AllKnownTypes()).To(HaveKey(internalGv.WithKind("WatchEvent")))
emptyGv := schema.GroupVersion{Group: "", Version: "v1"}
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status")))
})
It("should be able to add types from other Builders", func() {
gv1 := schema.GroupVersion{Group: "core", Version: "v1"}
b1 := (&scheme.Builder{GroupVersion: gv1}).Register(&corev1.Pod{}, &corev1.PodList{})
gv2 := schema.GroupVersion{Group: "apps", Version: "v1"}
s, err := (&scheme.Builder{GroupVersion: gv2}).
Register(&appsv1.Deployment{}).
Register(&appsv1.DeploymentList{}).
RegisterAll(b1).
Build()
Expect(err).NotTo(HaveOccurred())
Expect(s.AllKnownTypes()).To(HaveLen(25))
// Types from b1
Expect(s.AllKnownTypes()[gv1.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{})))
Expect(s.AllKnownTypes()[gv1.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{})))
// Types from b2
Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{})))
Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{})))
// Base types
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("DeleteOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ExportOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("GetOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ListOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("WatchEvent")))
internalGv1 := schema.GroupVersion{Group: "core", Version: "__internal"}
Expect(s.AllKnownTypes()).To(HaveKey(internalGv1.WithKind("WatchEvent")))
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("DeleteOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ExportOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("GetOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ListOptions")))
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("WatchEvent")))
internalGv2 := schema.GroupVersion{Group: "apps", Version: "__internal"}
Expect(s.AllKnownTypes()).To(HaveKey(internalGv2.WithKind("WatchEvent")))
emptyGv := schema.GroupVersion{Group: "", Version: "v1"}
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions")))
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status")))
})
})
})