Skip to content

Commit ad084aa

Browse files
committed
try to fix test on Win
1 parent fddefbd commit ad084aa

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

agent/agentscripts/agentscripts_test.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package agentscripts_test
33
import (
44
"context"
55
"path/filepath"
6+
"runtime"
67
"testing"
78
"time"
89

@@ -17,6 +18,7 @@ import (
1718
"github.com/coder/coder/v2/agent/agentssh"
1819
"github.com/coder/coder/v2/codersdk"
1920
"github.com/coder/coder/v2/codersdk/agentsdk"
21+
"github.com/coder/coder/v2/testutil"
2022
)
2123

2224
func TestMain(m *testing.M) {
@@ -58,17 +60,41 @@ func TestEnv(t *testing.T) {
5860
})
5961
defer runner.Close()
6062
id := uuid.New()
63+
script := "echo $CODER_SCRIPT_DATA_DIR\necho $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+
}
6170
err := runner.Init([]codersdk.WorkspaceAgentScript{{
6271
LogSourceID: id,
63-
Script: "echo $CODER_SCRIPT_DATA_DIR\necho $CODER_SCRIPT_BIN_DIR\n",
72+
Script: script,
6473
}})
6574
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 {
6779
return true
6880
}))
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())
7298
}
7399

74100
func TestTimeout(t *testing.T) {

0 commit comments

Comments
 (0)