Skip to content

Commit 4ea0ed7

Browse files
committed
fix: cli: clitest_test: avoid calling t.FailNow outside main goroutine
1 parent 5530f2a commit 4ea0ed7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cli/clitest/clitest_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package clitest_test
22

33
import (
4+
"context"
45
"testing"
6+
"time"
57

68
"github.com/stretchr/testify/require"
79
"go.uber.org/goleak"
@@ -17,16 +19,20 @@ func TestMain(m *testing.M) {
1719

1820
func TestCli(t *testing.T) {
1921
t.Parallel()
22+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
23+
defer cancelFunc()
2024
clitest.CreateTemplateVersionSource(t, nil)
2125
client := coderdtest.New(t, nil)
2226
cmd, config := clitest.New(t)
2327
clitest.SetupConfig(t, client, config)
2428
pty := ptytest.New(t)
2529
cmd.SetIn(pty.Input())
2630
cmd.SetOut(pty.Output())
31+
errC := make(chan error)
2732
go func() {
28-
err := cmd.Execute()
29-
require.NoError(t, err)
33+
errC <- cmd.ExecuteContext(ctx)
3034
}()
3135
pty.ExpectMatch("coder")
36+
cancelFunc()
37+
require.NoError(t, <-errC)
3238
}

0 commit comments

Comments
 (0)