k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/apis/autoscaling/v2beta1/conversion_test.go (about) 1 /* 2 Copyright 2017 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 v2beta1 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/assert" 23 24 "k8s.io/api/autoscaling/v2beta1" 25 "k8s.io/apimachinery/pkg/runtime" 26 "k8s.io/kubernetes/pkg/apis/autoscaling" 27 ) 28 29 // Testing nil pointer panic uncovered by #70806 30 // TODO(yue9944882): Test nil/empty conversion across all resource types 31 func TestNilOrEmptyConversion(t *testing.T) { 32 scheme := runtime.NewScheme() 33 assert.NoError(t, RegisterConversions(scheme)) 34 35 testCases := []struct { 36 obj1 interface{} 37 obj2 interface{} 38 }{ 39 { 40 obj1: &autoscaling.ExternalMetricSource{}, 41 obj2: &v2beta1.ExternalMetricSource{}, 42 }, 43 { 44 obj1: &autoscaling.ExternalMetricStatus{}, 45 obj2: &v2beta1.ExternalMetricStatus{}, 46 }, 47 { 48 obj1: &autoscaling.PodsMetricSource{}, 49 obj2: &v2beta1.PodsMetricSource{}, 50 }, 51 { 52 obj1: &autoscaling.PodsMetricStatus{}, 53 obj2: &v2beta1.PodsMetricStatus{}, 54 }, 55 { 56 obj1: &autoscaling.ObjectMetricSource{}, 57 obj2: &v2beta1.ObjectMetricSource{}, 58 }, 59 { 60 obj1: &autoscaling.ObjectMetricStatus{}, 61 obj2: &v2beta1.ObjectMetricStatus{}, 62 }, 63 { 64 obj1: &autoscaling.ResourceMetricSource{}, 65 obj2: &v2beta1.ResourceMetricSource{}, 66 }, 67 { 68 obj1: &autoscaling.ResourceMetricStatus{}, 69 obj2: &v2beta1.ResourceMetricStatus{}, 70 }, 71 { 72 obj1: &autoscaling.HorizontalPodAutoscaler{}, 73 obj2: &v2beta1.HorizontalPodAutoscaler{}, 74 }, 75 { 76 obj1: &autoscaling.MetricTarget{}, 77 obj2: &v2beta1.CrossVersionObjectReference{}, 78 }, 79 } 80 for _, testCase := range testCases { 81 assert.NoError(t, scheme.Convert(testCase.obj1, testCase.obj2, nil)) 82 assert.NoError(t, scheme.Convert(testCase.obj2, testCase.obj1, nil)) 83 } 84 }