mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
fix: capture stderr in executil RunWithExecRunOpts (#25139)
Signed-off-by: Eugene Doudine <eugene.doudine@octopus.com>
This commit is contained in:
@@ -63,7 +63,7 @@ func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string,
|
||||
}
|
||||
|
||||
func RunWithExecRunOpts(cmd *exec.Cmd, opts ExecRunOpts) (string, error) {
|
||||
cmdOpts := CmdOpts{Timeout: timeout, FatalTimeout: fatalTimeout, Redactor: opts.Redactor, TimeoutBehavior: opts.TimeoutBehavior, SkipErrorLogging: opts.SkipErrorLogging}
|
||||
cmdOpts := CmdOpts{Timeout: timeout, FatalTimeout: fatalTimeout, Redactor: opts.Redactor, TimeoutBehavior: opts.TimeoutBehavior, SkipErrorLogging: opts.SkipErrorLogging, CaptureStderr: opts.CaptureStderr}
|
||||
span := tracing.NewLoggingTracer(log.NewLogrusLogger(log.NewWithCurrentConfig())).StartSpan(fmt.Sprintf("exec %v", cmd.Args[0]))
|
||||
span.SetBaggageItem("dir", cmd.Dir)
|
||||
if cmdOpts.Redactor != nil {
|
||||
|
||||
@@ -218,3 +218,11 @@ func TestRunCaptureStderr(t *testing.T) {
|
||||
assert.Equal(t, "hello world\nmy-error", output)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestRunWithExecRunOptsCaptureStderr(t *testing.T) {
|
||||
ctx := t.Context()
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", "echo hello world && echo my-error >&2 && exit 0")
|
||||
output, err := RunWithExecRunOpts(cmd, ExecRunOpts{CaptureStderr: true})
|
||||
assert.Equal(t, "hello world\nmy-error", output)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user