k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kubeadm/app/componentconfigs/utils_test.go (about) 1 /* 2 Copyright 2024 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 componentconfigs 18 19 import ( 20 "testing" 21 22 "k8s.io/apimachinery/pkg/runtime/schema" 23 ) 24 25 func TestUnsupportedConfigVersionsError(t *testing.T) { 26 tests := []struct { 27 name string 28 errs UnsupportedConfigVersionsErrorMap 29 wantError string 30 wantErrorMap string 31 }{ 32 { 33 name: "only one error", 34 errs: UnsupportedConfigVersionsErrorMap{ 35 "foo": &UnsupportedConfigVersionError{ 36 OldVersion: schema.GroupVersion{ 37 Group: "admissionregistration.k8s.io", 38 Version: "v1beta1", 39 }, 40 CurrentVersion: schema.GroupVersion{ 41 Group: "admissionregistration.k8s.io", 42 Version: "v1", 43 }, 44 }, 45 }, 46 wantError: "unsupported apiVersion \"admissionregistration.k8s.io/v1beta1\", you may have to do manual conversion to \"admissionregistration.k8s.io/v1\" and run kubeadm again", 47 wantErrorMap: "multiple unsupported config version errors encountered:\n\t- unsupported apiVersion \"admissionregistration.k8s.io/v1beta1\", you may have to do manual conversion to \"admissionregistration.k8s.io/v1\" and run kubeadm again", 48 }, 49 { 50 name: "multiple errors", 51 errs: UnsupportedConfigVersionsErrorMap{ 52 "err1": &UnsupportedConfigVersionError{ 53 OldVersion: schema.GroupVersion{ 54 Group: "admissionregistration.k8s.io", 55 Version: "v1beta1", 56 }, 57 CurrentVersion: schema.GroupVersion{ 58 Group: "admissionregistration.k8s.io", 59 Version: "v1", 60 }, 61 }, 62 "err2": &UnsupportedConfigVersionError{ 63 OldVersion: schema.GroupVersion{ 64 Group: "node.k8s.io", 65 Version: "v1beta1", 66 }, 67 CurrentVersion: schema.GroupVersion{ 68 Group: "node.k8s.io", 69 Version: "v1", 70 }, 71 }, 72 }, 73 wantErrorMap: "multiple unsupported config version errors encountered:" + 74 "\n\t- unsupported apiVersion \"admissionregistration.k8s.io/v1beta1\", you may have to do manual conversion to \"admissionregistration.k8s.io/v1\" and run kubeadm again" + 75 "\n\t- unsupported apiVersion \"node.k8s.io/v1beta1\", you may have to do manual conversion to \"node.k8s.io/v1\" and run kubeadm again", 76 }, 77 } 78 for _, tt := range tests { 79 t.Run(tt.name, func(t *testing.T) { 80 if got := tt.errs.Error(); got != tt.wantErrorMap { 81 t.Errorf("UnsupportedConfigVersionsErrorMap.Error() = %v\n, want %v", got, tt.wantErrorMap) 82 } 83 if tt.wantError != "" { 84 for _, err := range tt.errs { 85 if got := err.Error(); got != tt.wantError { 86 t.Errorf("UnsupportedConfigVersionError.Error() = %v\n, want %v", got, tt.wantError) 87 break 88 } 89 } 90 } 91 }) 92 } 93 }