Helper function to run a command and return its stdout and stderr. We want to differentiate stdout and stderr instead of using CombinedOutput. We also want to differentiate between a command running successfully with output to stderr and a non-zero exit code.
(ctx context.Context, execer agentexec.Execer, cmd string, args ...string)
| 218 | // We also want to differentiate between a command running successfully with |
| 219 | // output to stderr and a non-zero exit code. |
| 220 | func run(ctx context.Context, execer agentexec.Execer, cmd string, args ...string) (stdout, stderr string, err error) { |
| 221 | var stdoutBuf, stderrBuf strings.Builder |
| 222 | execCmd := execer.CommandContext(ctx, cmd, args...) |
| 223 | execCmd.Stdout = &stdoutBuf |
| 224 | execCmd.Stderr = &stderrBuf |
| 225 | err = execCmd.Run() |
| 226 | stdout = strings.TrimSpace(stdoutBuf.String()) |
| 227 | stderr = strings.TrimSpace(stderrBuf.String()) |
| 228 | return stdout, stderr, err |
| 229 | } |
| 230 | |
| 231 | // dockerCLI is an implementation for Docker CLI that lists containers. |
| 232 | type dockerCLI struct { |
no test coverage detected