k8s.io/client-go@v0.31.1/tools/clientcmd/api/v1/defaults_test.go (about) 1 /* 2 Copyright 2021 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 v1 18 19 import ( 20 "testing" 21 22 "github.com/google/go-cmp/cmp" 23 ) 24 25 func TestSetDefaults_Config(t *testing.T) { 26 tests := []struct { 27 name string 28 in, wantOut *ExecConfig 29 }{ 30 { 31 name: "alpha exec API with empty interactive mode", 32 in: &ExecConfig{APIVersion: "client.authentication.k8s.io/v1alpha1"}, 33 wantOut: &ExecConfig{ 34 APIVersion: "client.authentication.k8s.io/v1alpha1", 35 InteractiveMode: IfAvailableExecInteractiveMode, 36 }, 37 }, 38 { 39 name: "beta exec API with empty interactive mode", 40 in: &ExecConfig{APIVersion: "client.authentication.k8s.io/v1beta1"}, 41 wantOut: &ExecConfig{ 42 APIVersion: "client.authentication.k8s.io/v1beta1", 43 InteractiveMode: IfAvailableExecInteractiveMode, 44 }, 45 }, 46 { 47 name: "alpha exec API with set interactive mode", 48 in: &ExecConfig{ 49 APIVersion: "client.authentication.k8s.io/v1alpha1", 50 InteractiveMode: NeverExecInteractiveMode, 51 }, 52 wantOut: &ExecConfig{ 53 APIVersion: "client.authentication.k8s.io/v1alpha1", 54 InteractiveMode: NeverExecInteractiveMode, 55 }, 56 }, 57 { 58 name: "beta exec API with set interactive mode", 59 in: &ExecConfig{ 60 APIVersion: "client.authentication.k8s.io/v1beta1", 61 InteractiveMode: NeverExecInteractiveMode, 62 }, 63 wantOut: &ExecConfig{ 64 APIVersion: "client.authentication.k8s.io/v1beta1", 65 InteractiveMode: NeverExecInteractiveMode, 66 }, 67 }, 68 { 69 name: "v1 exec API with empty interactive mode", 70 in: &ExecConfig{APIVersion: "client.authentication.k8s.io/v1"}, 71 wantOut: &ExecConfig{APIVersion: "client.authentication.k8s.io/v1"}, 72 }, 73 } 74 for _, test := range tests { 75 test := test 76 t.Run(test.name, func(t *testing.T) { 77 gotOut := test.in.DeepCopy() 78 SetDefaults_ExecConfig(gotOut) 79 if diff := cmp.Diff(test.wantOut, gotOut); diff != "" { 80 t.Errorf("unexpected defaulting; -want, +got:\n %s", diff) 81 } 82 }) 83 } 84 }