@@ -2,9 +2,11 @@ package cli_test
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"os"
6
7
"testing"
7
8
9
+ "github.com/stretchr/testify/assert"
8
10
"github.com/stretchr/testify/require"
9
11
10
12
"github.com/coder/coder/cli/clitest"
@@ -13,6 +15,7 @@ import (
13
15
"github.com/coder/coder/provisioner/echo"
14
16
"github.com/coder/coder/provisionersdk/proto"
15
17
"github.com/coder/coder/pty/ptytest"
18
+ "github.com/coder/coder/testutil"
16
19
)
17
20
18
21
var provisionCompleteWithAgent = []* proto.Provision_Response {
@@ -290,11 +293,23 @@ func TestTemplateCreate(t *testing.T) {
290
293
removeTmpDirUntilSuccessAfterTest (t , tempDir )
291
294
variablesFile , _ := os .CreateTemp (tempDir , "variables*.yaml" )
292
295
_ , _ = variablesFile .WriteString (`second_variable: foobar` )
296
+
297
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitShort )
298
+ defer cancel ()
299
+
293
300
inv , root := clitest .New (t , "templates" , "create" , "my-template" , "--directory" , source , "--test.provisioner" , string (database .ProvisionerTypeEcho ), "--variables-file" , variablesFile .Name ())
294
301
clitest .SetupConfig (t , client , root )
302
+ inv = inv .WithContext (ctx )
295
303
pty := ptytest .New (t ).Attach (inv )
296
304
297
- clitest .Start (t , inv )
305
+ // We expect the cli to return an error, so we have to handle it
306
+ // ourselves.
307
+ go func () {
308
+ cancel ()
309
+ err := inv .Run ()
310
+ assert .Error (t , err )
311
+ }()
312
+
298
313
matches := []struct {
299
314
match string
300
315
write string
@@ -307,6 +322,8 @@ func TestTemplateCreate(t *testing.T) {
307
322
pty .WriteLine (m .write )
308
323
}
309
324
}
325
+
326
+ <- ctx .Done ()
310
327
})
311
328
312
329
t .Run ("WithVariablesFileWithTheRequiredValue" , func (t * testing.T ) {
@@ -390,7 +407,9 @@ func TestTemplateCreate(t *testing.T) {
390
407
}
391
408
for _ , m := range matches {
392
409
pty .ExpectMatch (m .match )
393
- pty .WriteLine (m .write )
410
+ if len (m .write ) > 0 {
411
+ pty .WriteLine (m .write )
412
+ }
394
413
}
395
414
})
396
415
}
0 commit comments