(t *testing.T)
| 46 | ) |
| 47 | |
| 48 | func 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 | |
| 104 | func TestGetEnv(t *testing.T) { |
| 105 | test := struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…