|
| 1 | +package scheme_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | + appsv1 "k8s.io/api/apps/v1" |
| 9 | + corev1 "k8s.io/api/core/v1" |
| 10 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 11 | + "sigs.k8s.io/controller-runtime/pkg/runtime/scheme" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = Describe("Scheme", func() { |
| 15 | + Describe("Builder", func() { |
| 16 | + It("should provide a Scheme with the types registered", func() { |
| 17 | + gv := schema.GroupVersion{Group: "core", Version: "v1"} |
| 18 | + |
| 19 | + s, err := (&scheme.Builder{GroupVersion: gv}). |
| 20 | + Register(&corev1.Pod{}, &corev1.PodList{}). |
| 21 | + Build() |
| 22 | + Expect(err).NotTo(HaveOccurred()) |
| 23 | + |
| 24 | + Expect(s.AllKnownTypes()).To(HaveLen(13)) |
| 25 | + Expect(s.AllKnownTypes()[gv.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{}))) |
| 26 | + Expect(s.AllKnownTypes()[gv.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{}))) |
| 27 | + |
| 28 | + // Base types |
| 29 | + Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("DeleteOptions"))) |
| 30 | + Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ExportOptions"))) |
| 31 | + Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("GetOptions"))) |
| 32 | + Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("ListOptions"))) |
| 33 | + Expect(s.AllKnownTypes()).To(HaveKey(gv.WithKind("WatchEvent"))) |
| 34 | + |
| 35 | + internalGv := schema.GroupVersion{Group: "core", Version: "__internal"} |
| 36 | + Expect(s.AllKnownTypes()).To(HaveKey(internalGv.WithKind("WatchEvent"))) |
| 37 | + |
| 38 | + emptyGv := schema.GroupVersion{Group: "", Version: "v1"} |
| 39 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup"))) |
| 40 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList"))) |
| 41 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList"))) |
| 42 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions"))) |
| 43 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status"))) |
| 44 | + }) |
| 45 | + |
| 46 | + It("should be able to add types from other Builders", func() { |
| 47 | + gv1 := schema.GroupVersion{Group: "core", Version: "v1"} |
| 48 | + b1 := (&scheme.Builder{GroupVersion: gv1}).Register(&corev1.Pod{}, &corev1.PodList{}) |
| 49 | + |
| 50 | + gv2 := schema.GroupVersion{Group: "apps", Version: "v1"} |
| 51 | + s, err := (&scheme.Builder{GroupVersion: gv2}). |
| 52 | + Register(&appsv1.Deployment{}). |
| 53 | + Register(&appsv1.DeploymentList{}). |
| 54 | + RegisterAll(b1). |
| 55 | + Build() |
| 56 | + |
| 57 | + Expect(err).NotTo(HaveOccurred()) |
| 58 | + Expect(s.AllKnownTypes()).To(HaveLen(21)) |
| 59 | + |
| 60 | + // Types from b1 |
| 61 | + Expect(s.AllKnownTypes()[gv1.WithKind("Pod")]).To(Equal(reflect.TypeOf(corev1.Pod{}))) |
| 62 | + Expect(s.AllKnownTypes()[gv1.WithKind("PodList")]).To(Equal(reflect.TypeOf(corev1.PodList{}))) |
| 63 | + |
| 64 | + // Types from b2 |
| 65 | + Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{}))) |
| 66 | + Expect(s.AllKnownTypes()[gv2.WithKind("Deployment")]).To(Equal(reflect.TypeOf(appsv1.Deployment{}))) |
| 67 | + |
| 68 | + // Base types |
| 69 | + Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("DeleteOptions"))) |
| 70 | + Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ExportOptions"))) |
| 71 | + Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("GetOptions"))) |
| 72 | + Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("ListOptions"))) |
| 73 | + Expect(s.AllKnownTypes()).To(HaveKey(gv1.WithKind("WatchEvent"))) |
| 74 | + |
| 75 | + internalGv1 := schema.GroupVersion{Group: "core", Version: "__internal"} |
| 76 | + Expect(s.AllKnownTypes()).To(HaveKey(internalGv1.WithKind("WatchEvent"))) |
| 77 | + |
| 78 | + Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("DeleteOptions"))) |
| 79 | + Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ExportOptions"))) |
| 80 | + Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("GetOptions"))) |
| 81 | + Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("ListOptions"))) |
| 82 | + Expect(s.AllKnownTypes()).To(HaveKey(gv2.WithKind("WatchEvent"))) |
| 83 | + |
| 84 | + internalGv2 := schema.GroupVersion{Group: "apps", Version: "__internal"} |
| 85 | + Expect(s.AllKnownTypes()).To(HaveKey(internalGv2.WithKind("WatchEvent"))) |
| 86 | + |
| 87 | + emptyGv := schema.GroupVersion{Group: "", Version: "v1"} |
| 88 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup"))) |
| 89 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList"))) |
| 90 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList"))) |
| 91 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions"))) |
| 92 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status"))) |
| 93 | + }) |
| 94 | + }) |
| 95 | +}) |
0 commit comments