@@ -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,7 +501,7 @@ func TestAgent(t *testing.T) {
497
501
}
498
502
}()
499
503
500
- conn , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {}, 0 )
504
+ conn , _ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {}, 0 )
501
505
require .True (t , conn .AwaitReachable (context .Background ()))
502
506
conn1 , err := conn .DialContext (context .Background (), l .Addr ().Network (), l .Addr ().String ())
503
507
require .NoError (t , err )
@@ -518,7 +522,7 @@ func TestAgent(t *testing.T) {
518
522
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
519
523
defer cancel ()
520
524
derpMap := tailnettest .RunDERPAndSTUN (t )
521
- conn , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {
525
+ conn , _ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {
522
526
DERPMap : derpMap ,
523
527
}, 0 )
524
528
defer conn .Close ()
@@ -601,7 +605,7 @@ func TestAgent(t *testing.T) {
601
605
}
602
606
603
607
func setupSSHCommand (t * testing.T , beforeArgs []string , afterArgs []string ) * exec.Cmd {
604
- agentConn , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {}, 0 )
608
+ agentConn , _ , _ := setupAgent (t , codersdk.WorkspaceAgentMetadata {}, 0 )
605
609
listener , err := net .Listen ("tcp" , "127.0.0.1:0" )
606
610
require .NoError (t , err )
607
611
waitGroup := sync.WaitGroup {}
@@ -644,7 +648,7 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
644
648
func setupSSHSession (t * testing.T , options codersdk.WorkspaceAgentMetadata ) * ssh.Session {
645
649
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
646
650
defer cancel ()
647
- conn , _ := setupAgent (t , options , 0 )
651
+ conn , _ , _ := setupAgent (t , options , 0 )
648
652
sshClient , err := conn .SSHClient (ctx )
649
653
require .NoError (t , err )
650
654
t .Cleanup (func () {
@@ -664,13 +668,15 @@ func (c closeFunc) Close() error {
664
668
func setupAgent (t * testing.T , metadata codersdk.WorkspaceAgentMetadata , ptyTimeout time.Duration ) (
665
669
* codersdk.AgentConn ,
666
670
<- chan * codersdk.AgentStats ,
671
+ afero.Fs ,
667
672
) {
668
673
if metadata .DERPMap == nil {
669
674
metadata .DERPMap = tailnettest .RunDERPAndSTUN (t )
670
675
}
671
676
coordinator := tailnet .NewCoordinator ()
672
677
agentID := uuid .New ()
673
678
statsCh := make (chan * codersdk.AgentStats )
679
+ fs := afero .NewMemMapFs ()
674
680
closer := agent .New (agent.Options {
675
681
Client : & client {
676
682
t : t ,
@@ -679,6 +685,7 @@ func setupAgent(t *testing.T, metadata codersdk.WorkspaceAgentMetadata, ptyTimeo
679
685
statsChan : statsCh ,
680
686
coordinator : coordinator ,
681
687
},
688
+ Filesystem : fs ,
682
689
Logger : slogtest .Make (t , nil ).Leveled (slog .LevelDebug ),
683
690
ReconnectingPTYTimeout : ptyTimeout ,
684
691
})
@@ -704,7 +711,7 @@ func setupAgent(t *testing.T, metadata codersdk.WorkspaceAgentMetadata, ptyTimeo
704
711
conn .SetNodeCallback (sendNode )
705
712
return & codersdk.AgentConn {
706
713
Conn : conn ,
707
- }, statsCh
714
+ }, statsCh , fs
708
715
}
709
716
710
717
var dialTestPayload = []byte ("dean-was-here123" )
0 commit comments