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