MCPcopy
hub / github.com/kubernetes/kubectl / TestGetRestartPolicy

Function TestGetRestartPolicy

pkg/cmd/run/run_test.go:48–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46)
47
48func TestGetRestartPolicy(t *testing.T) {
49 tests := []struct {
50 input string
51 interactive bool
52 expected corev1.RestartPolicy
53 expectErr bool
54 }{
55 {
56 input: "",
57 expected: corev1.RestartPolicyAlways,
58 },
59 {
60 input: "",
61 interactive: true,
62 expected: corev1.RestartPolicyOnFailure,
63 },
64 {
65 input: string(corev1.RestartPolicyAlways),
66 interactive: true,
67 expected: corev1.RestartPolicyAlways,
68 },
69 {
70 input: string(corev1.RestartPolicyNever),
71 interactive: true,
72 expected: corev1.RestartPolicyNever,
73 },
74 {
75 input: string(corev1.RestartPolicyAlways),
76 expected: corev1.RestartPolicyAlways,
77 },
78 {
79 input: string(corev1.RestartPolicyNever),
80 expected: corev1.RestartPolicyNever,
81 },
82 {
83 input: "foo",
84 expectErr: true,
85 },
86 }
87 for _, test := range tests {
88 cmd := &cobra.Command{}
89 cmd.Flags().String("restart", "", i18n.T("dummy restart flag)"))
90 cmd.Flags().Lookup("restart").Value.Set(test.input)
91 policy, err := getRestartPolicy(cmd, test.interactive)
92 if test.expectErr && err == nil {
93 t.Error("unexpected non-error")
94 }
95 if !test.expectErr && err != nil {
96 t.Errorf("unexpected error: %v", err)
97 }
98 if !test.expectErr && policy != test.expected {
99 t.Errorf("expected: %s, saw: %s (%s:%v)", test.expected, policy, test.input, test.interactive)
100 }
101 }
102}
103
104func TestGetEnv(t *testing.T) {
105 test := struct {

Callers

nothing calls this directly

Calls 5

TFunction · 0.92
getRestartPolicyFunction · 0.85
StringMethod · 0.65
LookupMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…