fix: Avoid dirtying stdout/stderr in test (#3165)

* fix: Default all clitest commands to io.Discard stdout/err

* fix: Never write to stdout or stderr in tests
This commit is contained in:
Mathias Fredriksson
2022-07-25 16:55:53 +03:00
committed by GitHub
parent ad2b29a571
commit 233aa17848
4 changed files with 13 additions and 7 deletions
+2 -1
View File
@@ -173,9 +173,10 @@ func TestConfigSSH(t *testing.T) {
home := filepath.Dir(filepath.Dir(sshConfigFile))
// #nosec
sshCmd := exec.Command("ssh", "-F", sshConfigFile, "coder."+workspace.Name, "echo", "test")
pty = ptytest.New(t)
// Set HOME because coder config is included from ~/.ssh/coder.
sshCmd.Env = append(sshCmd.Env, fmt.Sprintf("HOME=%s", home))
sshCmd.Stderr = os.Stderr
sshCmd.Stderr = pty.Output()
data, err := sshCmd.Output()
require.NoError(t, err)
require.Equal(t, "test", strings.TrimSpace(string(data)))