(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestOutputWithRichError(t *testing.T) { |
| 102 | tests := []struct { |
| 103 | name string |
| 104 | envValue string |
| 105 | cmd *exec.Cmd |
| 106 | expected string |
| 107 | expectedStdout string |
| 108 | }{ |
| 109 | { |
| 110 | name: "debug output in stdout when HELM_DEBUG is true", |
| 111 | envValue: "true", |
| 112 | cmd: exec.Command("echo", "test1"), |
| 113 | expected: "test1\n", |
| 114 | expectedStdout: "Executing echo test1\n", |
| 115 | }, |
| 116 | { |
| 117 | name: "non-debug output in stdout when HELM_DEBUG is false", |
| 118 | envValue: "false", |
| 119 | cmd: exec.Command("echo", "test2"), |
| 120 | expected: "test2\n", |
| 121 | expectedStdout: "", |
| 122 | }, |
| 123 | } |
| 124 | |
| 125 | for _, tt := range tests { |
| 126 | t.Run(tt.name, func(t *testing.T) { |
| 127 | t.Setenv("HELM_DEBUG", tt.envValue) |
| 128 | var ( |
| 129 | stdoutString string |
| 130 | outBytes []byte |
| 131 | funcErr, captureErr error |
| 132 | ) |
| 133 | stdoutString, captureErr = captureStdout(func() { |
| 134 | outBytes, funcErr = outputWithRichError(tt.cmd) |
| 135 | }) |
| 136 | require.NoError(t, captureErr) |
| 137 | require.NoError(t, funcErr) |
| 138 | require.Equalf(t, tt.expected, string(outBytes), "Expected %v but got %v", tt.expected, string(outBytes)) |
| 139 | require.Equalf(t, tt.expectedStdout, stdoutString, "Expected %v but got %v", tt.expectedStdout, stdoutString) |
| 140 | }) |
| 141 | } |
| 142 | } |
nothing calls this directly
no test coverage detected