sigs.k8s.io/controller-runtime@v0.18.2/pkg/scheme/scheme_test.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package scheme_test 18 19 import ( 20 "reflect" 21 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 . "github.com/onsi/gomega/gstruct" 25 appsv1 "k8s.io/api/apps/v1" 26 corev1 "k8s.io/api/core/v1" 27 "k8s.io/apimachinery/pkg/runtime/schema" 28 "sigs.k8s.io/controller-runtime/pkg/scheme" 29 ) 30 31 var _ = Describe("Scheme", func() { 32 Describe("Builder", func() { 33 It("should provide a Scheme with the types registered", func() { 34 gv := schema.GroupVersion{Group: "core", Version: "v1"} 35 36 s, err := (&scheme.Builder{GroupVersion: gv}). 37 Register(&corev1.Pod{}, &corev1.PodList{}). 38 Build() 39 Expect(err).NotTo(HaveOccurred()) 40 41 internalGv := schema.GroupVersion{Group: "core", Version: "__internal"} 42 emptyGv := schema.GroupVersion{Group: "", Version: "v1"} 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("GetOptions"): Ignore(), 53 gv.WithKind("ListOptions"): Ignore(), 54 gv.WithKind("WatchEvent"): Ignore(), 55 56 internalGv.WithKind("WatchEvent"): Ignore(), 57 58 emptyGv.WithKind("APIGroup"): Ignore(), 59 emptyGv.WithKind("APIGroupList"): Ignore(), 60 emptyGv.WithKind("APIResourceList"): Ignore(), 61 emptyGv.WithKind("APIVersions"): Ignore(), 62 emptyGv.WithKind("Status"): Ignore(), 63 })) 64 }) 65 66 It("should be able to add types from other Builders", func() { 67 gv1 := schema.GroupVersion{Group: "core", Version: "v1"} 68 b1 := (&scheme.Builder{GroupVersion: gv1}).Register(&corev1.Pod{}, &corev1.PodList{}) 69 70 gv2 := schema.GroupVersion{Group: "apps", Version: "v1"} 71 s, err := (&scheme.Builder{GroupVersion: gv2}). 72 Register(&appsv1.Deployment{}). 73 Register(&appsv1.DeploymentList{}). 74 RegisterAll(b1). 75 Build() 76 77 Expect(err).NotTo(HaveOccurred()) 78 internalGv1 := schema.GroupVersion{Group: "core", Version: "__internal"} 79 internalGv2 := schema.GroupVersion{Group: "apps", Version: "__internal"} 80 emptyGv := schema.GroupVersion{Group: "", Version: "v1"} 81 Expect(s.AllKnownTypes()).To(MatchAllKeys(Keys{ 82 // Types from b1 83 gv1.WithKind("Pod"): Equal(reflect.TypeOf(corev1.Pod{})), 84 gv1.WithKind("PodList"): Equal(reflect.TypeOf(corev1.PodList{})), 85 86 // Types from b2 87 gv2.WithKind("Deployment"): Equal(reflect.TypeOf(appsv1.Deployment{})), 88 gv2.WithKind("DeploymentList"): Equal(reflect.TypeOf(appsv1.DeploymentList{})), 89 90 // Base types 91 gv1.WithKind("CreateOptions"): Ignore(), 92 gv1.WithKind("UpdateOptions"): Ignore(), 93 gv1.WithKind("PatchOptions"): Ignore(), 94 gv1.WithKind("DeleteOptions"): Ignore(), 95 gv1.WithKind("GetOptions"): Ignore(), 96 gv1.WithKind("ListOptions"): Ignore(), 97 gv1.WithKind("WatchEvent"): Ignore(), 98 99 internalGv1.WithKind("WatchEvent"): Ignore(), 100 101 gv2.WithKind("CreateOptions"): Ignore(), 102 gv2.WithKind("UpdateOptions"): Ignore(), 103 gv2.WithKind("PatchOptions"): Ignore(), 104 gv2.WithKind("DeleteOptions"): Ignore(), 105 gv2.WithKind("GetOptions"): Ignore(), 106 gv2.WithKind("ListOptions"): Ignore(), 107 gv2.WithKind("WatchEvent"): Ignore(), 108 109 internalGv2.WithKind("WatchEvent"): Ignore(), 110 111 emptyGv.WithKind("APIGroup"): Ignore(), 112 emptyGv.WithKind("APIGroupList"): Ignore(), 113 emptyGv.WithKind("APIResourceList"): Ignore(), 114 emptyGv.WithKind("APIVersions"): Ignore(), 115 emptyGv.WithKind("Status"): Ignore(), 116 })) 117 }) 118 }) 119 })