k8s.io/kube-openapi@v0.0.0-20240228011516-70dd3763d340/pkg/util/util_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 util 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestCanonicalName(t *testing.T) { 25 26 var tests = []struct { 27 input string 28 expected string 29 }{ 30 {"k8s.io/api/core/v1.Pod", "io.k8s.api.core.v1.Pod"}, 31 {"k8s.io/api/networking/v1/NetworkPolicy", "io.k8s.api.networking.v1.NetworkPolicy"}, 32 {"k8s.io/api/apps/v1beta2.Scale", "io.k8s.api.apps.v1beta2.Scale"}, 33 {"servicecatalog.k8s.io/foo/bar/v1alpha1.Baz", "io.k8s.servicecatalog.foo.bar.v1alpha1.Baz"}, 34 } 35 for _, test := range tests { 36 if got := ToRESTFriendlyName(test.input); got != test.expected { 37 t.Errorf("ToRESTFriendlyName(%q) = %v", test.input, got) 38 } 39 } 40 } 41 42 type TestType struct{} 43 44 func TestGetCanonicalTypeName(t *testing.T) { 45 46 var tests = []struct { 47 input interface{} 48 expected string 49 }{ 50 {TestType{}, "k8s.io/kube-openapi/pkg/util.TestType"}, 51 {&TestType{}, "k8s.io/kube-openapi/pkg/util.TestType"}, 52 } 53 for _, test := range tests { 54 if got := GetCanonicalTypeName(test.input); got != test.expected { 55 t.Errorf("GetCanonicalTypeName(%q) = %v", reflect.TypeOf(test.input), got) 56 } 57 } 58 }