...
1
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 }
94
View as plain text