@@ -43,6 +43,10 @@ import (
43
43
"github.com/coder/coder/v2/testutil"
44
44
)
45
45
46
+ const (
47
+ startupScriptPattern = "i-am-ready"
48
+ )
49
+
46
50
func setupWorkspaceForAgent (t * testing.T , mutate func ([]* proto.Agent ) []* proto.Agent ) (* codersdk.Client , codersdk.Workspace , string ) {
47
51
t .Helper ()
48
52
if mutate == nil {
@@ -68,6 +72,12 @@ func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.A
68
72
Auth : & proto.Agent_Token {
69
73
Token : agentToken ,
70
74
},
75
+ Scripts : []* proto.Script {
76
+ {
77
+ Script : fmt .Sprintf ("echo '%s'" , startupScriptPattern ),
78
+ RunOnStart : true ,
79
+ },
80
+ },
71
81
}}),
72
82
}},
73
83
},
@@ -393,12 +403,6 @@ func TestSSH(t *testing.T) {
393
403
394
404
client , workspace , agentToken := setupWorkspaceForAgent (t , nil )
395
405
396
- _ = agenttest .New (t , client .URL , agentToken )
397
- coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
398
-
399
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
400
- defer cancel ()
401
-
402
406
inv , root := clitest .New (t ,
403
407
"ssh" ,
404
408
workspace .Name ,
@@ -408,14 +412,23 @@ func TestSSH(t *testing.T) {
408
412
clitest .SetupConfig (t , client , root )
409
413
pty := ptytest .New (t ).Attach (inv )
410
414
inv .Stderr = pty .Output ()
415
+
416
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
417
+ defer cancel ()
418
+
411
419
cmdDone := tGo (t , func () {
412
420
err := inv .WithContext (ctx ).Run ()
413
421
assert .NoError (t , err , "ssh command failed" )
414
422
})
415
423
416
- // Wait for the prompt or any output really to indicate the command has
417
- // started and accepting input on stdin.
418
- _ = pty .Peek (ctx , 1 )
424
+ // Agent is still starting
425
+ pty .ExpectMatch ("Waiting" )
426
+
427
+ _ = agenttest .New (t , client .URL , agentToken )
428
+ coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
429
+
430
+ // Startup script has just finished
431
+ pty .ExpectMatch (startupScriptPattern )
419
432
420
433
// Download the test page
421
434
pty .WriteLine ("curl localhost:8222" )
0 commit comments