Skip to content

Commit 3998794

Browse files
committed
fix: cli: list_test: avoid calling t.FailNow outside main goroutine
1 parent 4ea0ed7 commit 3998794

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cli/list_test.go

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

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

68
"github.com/stretchr/testify/require"
79

@@ -14,6 +16,8 @@ func TestList(t *testing.T) {
1416
t.Parallel()
1517
t.Run("Single", func(t *testing.T) {
1618
t.Parallel()
19+
ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
20+
defer cancelFunc()
1721
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerD: true})
1822
user := coderdtest.CreateFirstUser(t, client)
1923
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
@@ -23,17 +27,16 @@ func TestList(t *testing.T) {
2327
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
2428
cmd, root := clitest.New(t, "ls")
2529
clitest.SetupConfig(t, client, root)
26-
doneChan := make(chan struct{})
2730
pty := ptytest.New(t)
2831
cmd.SetIn(pty.Input())
2932
cmd.SetOut(pty.Output())
33+
errC := make(chan error)
3034
go func() {
31-
defer close(doneChan)
32-
err := cmd.Execute()
33-
require.NoError(t, err)
35+
errC <- cmd.ExecuteContext(ctx)
3436
}()
3537
pty.ExpectMatch(workspace.Name)
3638
pty.ExpectMatch("Running")
37-
<-doneChan
39+
cancelFunc()
40+
require.NoError(t, <-errC)
3841
})
3942
}

0 commit comments

Comments
 (0)