@@ -61,7 +61,7 @@ func TestAgent(t *testing.T) {
61
61
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
62
62
defer cancel ()
63
63
64
- conn ,stats := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
64
+ conn ,stats , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
65
65
66
66
sshClient ,err := conn .SSHClient (ctx )
67
67
require .NoError (t ,err )
@@ -81,7 +81,7 @@ func TestAgent(t *testing.T) {
81
81
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
82
82
defer cancel ()
83
83
84
- conn ,stats := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
84
+ conn ,stats , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
85
85
86
86
ptyConn ,err := conn .ReconnectingPTY (ctx ,uuid .NewString (),128 ,128 ,"/bin/bash" )
87
87
require .NoError (t ,err )
@@ -231,7 +231,7 @@ func TestAgent(t *testing.T) {
231
231
if runtime .GOOS == "windows" {
232
232
home = "/" + strings .ReplaceAll (home ,"\\ " ,"/" )
233
233
}
234
- conn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
234
+ conn ,_ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
235
235
sshClient ,err := conn .SSHClient (ctx )
236
236
require .NoError (t ,err )
237
237
defer sshClient .Close ()
@@ -261,7 +261,7 @@ func TestAgent(t *testing.T) {
261
261
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
262
262
defer cancel ()
263
263
264
- conn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
264
+ conn ,_ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
265
265
sshClient ,err := conn .SSHClient (ctx )
266
266
require .NoError (t ,err )
267
267
defer sshClient .Close ()
@@ -360,19 +360,23 @@ func TestAgent(t *testing.T) {
360
360
361
361
t .Run ("StartupScript" ,func (t * testing.T ) {
362
362
t .Parallel ()
363
- tempPath := filepath .Join (t .TempDir (),"content.txt" )
364
- content := "somethingnice"
365
- setupAgent (t , codersdk.WorkspaceAgentMetadata {
366
- StartupScript :fmt .Sprintf ("echo %s > %s" ,content ,tempPath ),
363
+ if runtime .GOOS == "windows" {
364
+ t .Skip ("This test doesn't work on Windows for some reason..." )
365
+ }
366
+ content := "output"
367
+ _ ,_ ,fs := setupAgent (t , codersdk.WorkspaceAgentMetadata {
368
+ StartupScript :"echo " + content ,
367
369
},0 )
368
-
369
370
var gotContent string
370
371
require .Eventually (t ,func ()bool {
371
- content ,err := os .ReadFile (tempPath )
372
+ outputPath := filepath .Join (os .TempDir (),"coder-startup-script.log" )
373
+ content ,err := afero .ReadFile (fs ,outputPath )
372
374
if err != nil {
375
+ t .Logf ("read file %q: %s" ,outputPath ,err )
373
376
return false
374
377
}
375
378
if len (content )== 0 {
379
+ t .Logf ("no content in %q" ,outputPath )
376
380
return false
377
381
}
378
382
if runtime .GOOS == "windows" {
@@ -384,7 +388,7 @@ func TestAgent(t *testing.T) {
384
388
}
385
389
gotContent = string (content )
386
390
return true
387
- },testutil .WaitMedium ,testutil .IntervalMedium )
391
+ },testutil .WaitShort ,testutil .IntervalMedium )
388
392
require .Equal (t ,content ,strings .TrimSpace (gotContent ))
389
393
})
390
394
@@ -400,7 +404,7 @@ func TestAgent(t *testing.T) {
400
404
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
401
405
defer cancel ()
402
406
403
- conn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
407
+ conn ,_ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
404
408
id := uuid .NewString ()
405
409
netConn ,err := conn .ReconnectingPTY (ctx ,id ,100 ,100 ,"/bin/bash" )
406
410
require .NoError (t ,err )
@@ -497,13 +501,8 @@ func TestAgent(t *testing.T) {
497
501
}
498
502
}()
499
503
500
- conn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
501
- require .Eventually (t ,func ()bool {
502
- ctx ,cancelFunc := context .WithTimeout (context .Background (),testutil .IntervalFast )
503
- defer cancelFunc ()
504
- _ ,err := conn .Ping (ctx )
505
- return err == nil
506
- },testutil .WaitMedium ,testutil .IntervalFast )
504
+ conn ,_ ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
505
+ require .True (t ,conn .AwaitReachable (context .Background ()))
507
506
conn1 ,err := conn .DialContext (context .Background (),l .Addr ().Network (),l .Addr ().String ())
508
507
require .NoError (t ,err )
509
508
defer conn1 .Close ()
@@ -523,7 +522,7 @@ func TestAgent(t *testing.T) {
523
522
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
524
523
defer cancel ()
525
524
derpMap := tailnettest .RunDERPAndSTUN (t )
526
- conn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {
525
+ conn ,_ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {
527
526
DERPMap :derpMap ,
528
527
},0 )
529
528
defer conn .Close ()
@@ -606,7 +605,7 @@ func TestAgent(t *testing.T) {
606
605
}
607
606
608
607
func setupSSHCommand (t * testing.T ,beforeArgs []string ,afterArgs []string )* exec.Cmd {
609
- agentConn ,_ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
608
+ agentConn ,_ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {},0 )
610
609
listener ,err := net .Listen ("tcp" ,"127.0.0.1:0" )
611
610
require .NoError (t ,err )
612
611
waitGroup := sync.WaitGroup {}
@@ -649,7 +648,7 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
649
648
func setupSSHSession (t * testing.T ,options codersdk.WorkspaceAgentMetadata )* ssh.Session {
650
649
ctx ,cancel := context .WithTimeout (context .Background (),testutil .WaitLong )
651
650
defer cancel ()
652
- conn ,_ := setupAgent (t ,options ,0 )
651
+ conn ,_ , _ := setupAgent (t ,options ,0 )
653
652
sshClient ,err := conn .SSHClient (ctx )
654
653
require .NoError (t ,err )
655
654
t .Cleanup (func () {
@@ -669,13 +668,15 @@ func (c closeFunc) Close() error {
669
668
func setupAgent (t * testing.T ,metadata codersdk.WorkspaceAgentMetadata ,ptyTimeout time.Duration ) (
670
669
* codersdk.AgentConn ,
671
670
<- chan * codersdk.AgentStats ,
671
+ afero.Fs ,
672
672
) {
673
673
if metadata .DERPMap == nil {
674
674
metadata .DERPMap = tailnettest .RunDERPAndSTUN (t )
675
675
}
676
676
coordinator := tailnet .NewCoordinator ()
677
677
agentID := uuid .New ()
678
678
statsCh := make (chan * codersdk.AgentStats )
679
+ fs := afero .NewMemMapFs ()
679
680
closer := agent .New (agent.Options {
680
681
Client :& client {
681
682
t :t ,
@@ -684,6 +685,7 @@ func setupAgent(t *testing.T, metadata codersdk.WorkspaceAgentMetadata, ptyTimeo
684
685
statsChan :statsCh ,
685
686
coordinator :coordinator ,
686
687
},
688
+ Filesystem :fs ,
687
689
Logger :slogtest .Make (t ,nil ).Leveled (slog .LevelDebug ),
688
690
ReconnectingPTYTimeout :ptyTimeout ,
689
691
})
@@ -709,7 +711,7 @@ func setupAgent(t *testing.T, metadata codersdk.WorkspaceAgentMetadata, ptyTimeo
709
711
conn .SetNodeCallback (sendNode )
710
712
return & codersdk.AgentConn {
711
713
Conn :conn ,
712
- },statsCh
714
+ },statsCh , fs
713
715
}
714
716
715
717
var dialTestPayload = []byte ("dean-was-here123" )