1
1
package cli_test
2
2
3
3
import (
4
+ "context"
4
5
"testing"
6
+ "time"
5
7
6
8
"github.com/stretchr/testify/require"
7
9
@@ -14,6 +16,8 @@ func TestList(t *testing.T) {
14
16
t .Parallel ()
15
17
t .Run ("Single" , func (t * testing.T ) {
16
18
t .Parallel ()
19
+ ctx , cancelFunc := context .WithTimeout (context .Background (), 5 * time .Second )
20
+ defer cancelFunc ()
17
21
client := coderdtest .New (t , & coderdtest.Options {IncludeProvisionerD : true })
18
22
user := coderdtest .CreateFirstUser (t , client )
19
23
version := coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
@@ -23,17 +27,16 @@ func TestList(t *testing.T) {
23
27
coderdtest .AwaitWorkspaceBuildJob (t , client , workspace .LatestBuild .ID )
24
28
cmd , root := clitest .New (t , "ls" )
25
29
clitest .SetupConfig (t , client , root )
26
- doneChan := make (chan struct {})
27
30
pty := ptytest .New (t )
28
31
cmd .SetIn (pty .Input ())
29
32
cmd .SetOut (pty .Output ())
33
+ errC := make (chan error )
30
34
go func () {
31
- defer close (doneChan )
32
- err := cmd .Execute ()
33
- require .NoError (t , err )
35
+ errC <- cmd .ExecuteContext (ctx )
34
36
}()
35
37
pty .ExpectMatch (workspace .Name )
36
38
pty .ExpectMatch ("Running" )
37
- <- doneChan
39
+ cancelFunc ()
40
+ require .NoError (t , <- errC )
38
41
})
39
42
}
0 commit comments