fix: Guard against CLI cmd running after test exit (#1658)

* fix: Guard against CLI cmd running after test exit

* fix: cli: avoid calling t.FailNow in non-test-main goroutine

* fix: cli: server_test: avoid calling t.FailNow outside main goroutine

* fix: cli: clitest_test: avoid calling t.FailNow outside main goroutine

* fix: cli: list_test: avoid calling t.FailNow outside main goroutine

* fix: TestGitSSH use-of-t-after-exit

* fix: TestGitSSH "too many authentication failures"

Due to local SSH keys being given

* chore: clitest: fix TestCli

* chore: Simplify TestTemplateInit

Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
Mathias Fredriksson
2022-05-23 20:09:58 +03:00
committed by GitHub
co-authored by Cian Johnston
parent fa957d6d65
commit c8ed213347
7 changed files with 87 additions and 86 deletions
+13 -6
View File
@@ -63,9 +63,9 @@ func TestGitSSH(t *testing.T) {
clitest.SetupConfig(t, agentClient, root)
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
agentErrC := make(chan error)
go func() {
err := cmd.ExecuteContext(ctx)
require.NoError(t, err)
agentErrC <- cmd.ExecuteContext(ctx)
}()
coderdtest.AwaitWorkspaceAgents(t, client, workspace.LatestBuild.ID)
@@ -85,13 +85,13 @@ func TestGitSSH(t *testing.T) {
return ssh.KeysEqual(publicKey, key)
})
var inc int64
sshErrC := make(chan error)
go func() {
// as long as we get a successful session we don't care if the server errors
_ = ssh.Serve(l, func(s ssh.Session) {
atomic.AddInt64(&inc, 1)
t.Log("got authenticated session")
err := s.Exit(0)
require.NoError(t, err)
sshErrC <- s.Exit(0)
}, publicKeyOption)
}()
@@ -99,9 +99,16 @@ func TestGitSSH(t *testing.T) {
addr, ok := l.Addr().(*net.TCPAddr)
require.True(t, ok)
// set to agent config dir
cmd, _ = clitest.New(t, "gitssh", "--agent-url", agentClient.URL.String(), "--agent-token", agentToken, "--", fmt.Sprintf("-p%d", addr.Port), "-o", "StrictHostKeyChecking=no", "127.0.0.1")
err = cmd.ExecuteContext(context.Background())
gitsshCmd, _ := clitest.New(t, "gitssh", "--agent-url", agentClient.URL.String(), "--agent-token", agentToken, "--", fmt.Sprintf("-p%d", addr.Port), "-o", "StrictHostKeyChecking=no", "-o", "IdentitiesOnly=yes", "127.0.0.1")
err = gitsshCmd.ExecuteContext(context.Background())
require.NoError(t, err)
require.EqualValues(t, 1, inc)
err = <-sshErrC
require.NoError(t, err, "error in ssh session exit")
cancelFunc()
err = <-agentErrC
require.NoError(t, err, "error in agent execute")
})
}