Skip to content

Commit a11a908

Browse files
authored
Merge pull request #842 from Capstan/fix/createoptions-test
🏃 Use whole list matching for known types.
2 parents 2d4c487 + 87e0f8d commit a11a908

File tree

1 file changed

+61
-56
lines changed

1 file changed

+61
-56
lines changed

pkg/scheme/scheme_test.go

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
24+
. "github.com/onsi/gomega/gstruct"
2425
appsv1 "k8s.io/api/apps/v1"
2526
corev1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -37,28 +38,30 @@ var _ = Describe("Scheme", func() {
3738
Build()
3839
Expect(err).NotTo(HaveOccurred())
3940

40-
Expect(s.AllKnownTypes()).To(HaveLen(16))
41-
Expect(s.AllKnownTypes()[gv.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{})))
42-
Expect(s.AllKnownTypes()[gv.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{})))
43-
44-
// Base types
45-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("UpdateOptions")))
46-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("PatchOptions")))
47-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("DeleteOptions")))
48-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ExportOptions")))
49-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("GetOptions")))
50-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ListOptions")))
51-
Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("WatchEvent")))
52-
5341
internalGv := schema.GroupVersion{Group: "core", Version: "__internal"}
54-
Expect(s.AllKnownTypes()).To(HaveKey(internalGv.WithKind("WatchEvent")))
55-
5642
emptyGv := schema.GroupVersion{Group: "", Version: "v1"}
57-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup")))
58-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList")))
59-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList")))
60-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions")))
61-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status")))
43+
Expect(s.AllKnownTypes()).To(MatchAllKeys(Keys{
44+
gv.WithKind("Pod"): Equal(reflect.TypeOf(corev1.Pod{})),
45+
gv.WithKind("PodList"): Equal(reflect.TypeOf(corev1.PodList{})),
46+
47+
// Base types
48+
gv.WithKind("CreateOptions"): Ignore(),
49+
gv.WithKind("UpdateOptions"): Ignore(),
50+
gv.WithKind("PatchOptions"): Ignore(),
51+
gv.WithKind("DeleteOptions"): Ignore(),
52+
gv.WithKind("ExportOptions"): Ignore(),
53+
gv.WithKind("GetOptions"): Ignore(),
54+
gv.WithKind("ListOptions"): Ignore(),
55+
gv.WithKind("WatchEvent"): Ignore(),
56+
57+
internalGv.WithKind("WatchEvent"): Ignore(),
58+
59+
emptyGv.WithKind("APIGroup"): Ignore(),
60+
emptyGv.WithKind("APIGroupList"): Ignore(),
61+
emptyGv.WithKind("APIResourceList"): Ignore(),
62+
emptyGv.WithKind("APIVersions"): Ignore(),
63+
emptyGv.WithKind("Status"): Ignore(),
64+
}))
6265
})
6366

6467
It("should be able to add types from other Builders", func() {
@@ -73,45 +76,47 @@ var _ = Describe("Scheme", func() {
7376
Build()
7477

7578
Expect(err).NotTo(HaveOccurred())
76-
Expect(s.AllKnownTypes()).To(HaveLen(27))
77-
78-
// Types from b1
79-
Expect(s.AllKnownTypes()[gv1.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{})))
80-
Expect(s.AllKnownTypes()[gv1.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{})))
81-
82-
// Types from b2
83-
Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{})))
84-
Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{})))
85-
86-
// Base types
87-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("UpdateOptions")))
88-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("PatchOptions")))
89-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("DeleteOptions")))
90-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ExportOptions")))
91-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("GetOptions")))
92-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ListOptions")))
93-
Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("WatchEvent")))
94-
9579
internalGv1 := schema.GroupVersion{Group: "core", Version: "__internal"}
96-
Expect(s.AllKnownTypes()).To(HaveKey(internalGv1.WithKind("WatchEvent")))
97-
98-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("UpdateOptions")))
99-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("PatchOptions")))
100-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("DeleteOptions")))
101-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ExportOptions")))
102-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("GetOptions")))
103-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ListOptions")))
104-
Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("WatchEvent")))
105-
10680
internalGv2 := schema.GroupVersion{Group: "apps", Version: "__internal"}
107-
Expect(s.AllKnownTypes()).To(HaveKey(internalGv2.WithKind("WatchEvent")))
108-
10981
emptyGv := schema.GroupVersion{Group: "", Version: "v1"}
110-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup")))
111-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList")))
112-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList")))
113-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions")))
114-
Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status")))
82+
Expect(s.AllKnownTypes()).To(MatchAllKeys(Keys{
83+
// Types from b1
84+
gv1.WithKind("Pod"): Equal(reflect.TypeOf(corev1.Pod{})),
85+
gv1.WithKind("PodList"): Equal(reflect.TypeOf(corev1.PodList{})),
86+
87+
// Types from b2
88+
gv2.WithKind("Deployment"): Equal(reflect.TypeOf(appsv1.Deployment{})),
89+
gv2.WithKind("DeploymentList"): Equal(reflect.TypeOf(appsv1.DeploymentList{})),
90+
91+
// Base types
92+
gv1.WithKind("CreateOptions"): Ignore(),
93+
gv1.WithKind("UpdateOptions"): Ignore(),
94+
gv1.WithKind("PatchOptions"): Ignore(),
95+
gv1.WithKind("DeleteOptions"): Ignore(),
96+
gv1.WithKind("ExportOptions"): Ignore(),
97+
gv1.WithKind("GetOptions"): Ignore(),
98+
gv1.WithKind("ListOptions"): Ignore(),
99+
gv1.WithKind("WatchEvent"): Ignore(),
100+
101+
internalGv1.WithKind("WatchEvent"): Ignore(),
102+
103+
gv2.WithKind("CreateOptions"): Ignore(),
104+
gv2.WithKind("UpdateOptions"): Ignore(),
105+
gv2.WithKind("PatchOptions"): Ignore(),
106+
gv2.WithKind("DeleteOptions"): Ignore(),
107+
gv2.WithKind("ExportOptions"): Ignore(),
108+
gv2.WithKind("GetOptions"): Ignore(),
109+
gv2.WithKind("ListOptions"): Ignore(),
110+
gv2.WithKind("WatchEvent"): Ignore(),
111+
112+
internalGv2.WithKind("WatchEvent"): Ignore(),
113+
114+
emptyGv.WithKind("APIGroup"): Ignore(),
115+
emptyGv.WithKind("APIGroupList"): Ignore(),
116+
emptyGv.WithKind("APIResourceList"): Ignore(),
117+
emptyGv.WithKind("APIVersions"): Ignore(),
118+
emptyGv.WithKind("Status"): Ignore(),
119+
}))
115120
})
116121
})
117122
})

0 commit comments

Comments
 (0)