MCPcopy Index your code
hub / github.com/databus23/helm-diff / TestOutputWithRichError

Function TestOutputWithRichError

cmd/helpers_test.go:101–142  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

99}
100
101func 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}

Callers

nothing calls this directly

Calls 2

captureStdoutFunction · 0.85
outputWithRichErrorFunction · 0.85

Tested by

no test coverage detected