|
| 1 | +package scheme_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | + "k8s.io/api/core/v1" |
| 9 | + "k8s.io/apimachinery/pkg/runtime" |
| 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("NewAddToScheme", func() { |
| 16 | + It("should return a function that will add the types to the scheme", func() { |
| 17 | + gv := schema.GroupVersion{Group: "core", Version: "v1"} |
| 18 | + a := scheme.NewSchemeBuilder(gv, func() []runtime.Object { |
| 19 | + return []runtime.Object{&v1.Pod{}, &v1.PodList{}} |
| 20 | + }) |
| 21 | + s := runtime.NewScheme() |
| 22 | + |
| 23 | + Expect(a.AddToScheme(s)).To(Succeed()) |
| 24 | + Expect(s.AllKnownTypes()).To(HaveLen(13)) |
| 25 | + Expect(s.AllKnownTypes()[gv.WithKind("Pod")]).To(Equal(reflect.TypeOf(v1.Pod{}))) |
| 26 | + Expect(s.AllKnownTypes()[gv.WithKind("PodList")]).To(Equal(reflect.TypeOf(v1.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 | + emptyGv := schema.GroupVersion{Group: "", Version: "v1"} |
| 36 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroup"))) |
| 37 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIGroupList"))) |
| 38 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIResourceList"))) |
| 39 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("APIVersions"))) |
| 40 | + Expect(s.AllKnownTypes()).To(HaveKey(emptyGv.WithKind("Status"))) |
| 41 | + |
| 42 | + internalGv := schema.GroupVersion{Group: "core", Version: "__internal"} |
| 43 | + Expect(s.AllKnownTypes()).To(HaveKey(internalGv.WithKind("WatchEvent"))) |
| 44 | + }) |
| 45 | + }) |
| 46 | +}) |
0 commit comments