@@ -3,6 +3,7 @@ package agentscripts_test
3
3
import (
4
4
"context"
5
5
"path/filepath"
6
+ "runtime"
6
7
"testing"
7
8
"time"
8
9
@@ -17,6 +18,7 @@ import (
17
18
"github.com/coder/coder/v2/agent/agentssh"
18
19
"github.com/coder/coder/v2/codersdk"
19
20
"github.com/coder/coder/v2/codersdk/agentsdk"
21
+ "github.com/coder/coder/v2/testutil"
20
22
)
21
23
22
24
func TestMain (m * testing.M ) {
@@ -48,7 +50,7 @@ func TestExecuteBasic(t *testing.T) {
48
50
49
51
func TestEnv (t * testing.T ) {
50
52
t .Parallel ()
51
- logs := make (chan agentsdk.PatchLogs ,1 )
53
+ logs := make (chan agentsdk.PatchLogs ,2 )
52
54
runner := setup (t ,func (ctx context.Context ,req agentsdk.PatchLogs )error {
53
55
select {
54
56
case <- ctx .Done ():
@@ -58,17 +60,41 @@ func TestEnv(t *testing.T) {
58
60
})
59
61
defer runner .Close ()
60
62
id := uuid .New ()
63
+ script := "echo $CODER_SCRIPT_DATA_DIR\n echo $CODER_SCRIPT_BIN_DIR\n "
64
+ if runtime .GOOS == "windows" {
65
+ script = `
66
+ cmd.exe /c echo %CODER_SCRIPT_DATA_DIR%
67
+ cmd.exe /c echo %CODER_SCRIPT_BIN_DIR%
68
+ `
69
+ }
61
70
err := runner .Init ([]codersdk.WorkspaceAgentScript {{
62
71
LogSourceID :id ,
63
- Script :"echo $CODER_SCRIPT_DATA_DIR \n echo $CODER_SCRIPT_BIN_DIR \n " ,
72
+ Script :script ,
64
73
}})
65
74
require .NoError (t ,err )
66
- require .NoError (t ,runner .Execute (context .Background (),func (script codersdk.WorkspaceAgentScript )bool {
75
+
76
+ ctx := testutil .Context (t ,testutil .WaitLong )
77
+
78
+ require .NoError (t ,runner .Execute (ctx ,func (script codersdk.WorkspaceAgentScript )bool {
67
79
return true
68
80
}))
69
- log := <- logs
70
- require .Contains (t ,log .Logs [0 ].Output ,filepath .Join (runner .DataDir (),id .String ()))
71
- require .Contains (t ,log .Logs [1 ].Output ,runner .ScriptBinDir ())
81
+ var log []agentsdk.Log
82
+ for {
83
+ select {
84
+ case <- ctx .Done ():
85
+ require .Fail (t ,"timed out waiting for logs" )
86
+ case l := <- logs :
87
+ for _ ,l := range l .Logs {
88
+ t .Logf ("log: %s" ,l .Output )
89
+ }
90
+ log = append (log ,l .Logs ... )
91
+ }
92
+ if len (log )>= 2 {
93
+ break
94
+ }
95
+ }
96
+ require .Contains (t ,log [0 ].Output ,filepath .Join (runner .DataDir (),id .String ()))
97
+ require .Contains (t ,log [1 ].Output ,runner .ScriptBinDir ())
72
98
}
73
99
74
100
func TestTimeout (t * testing.T ) {