MCPcopy Index your code
hub / github.com/coder/coder / TestEnv

Function TestEnv

agent/agentscripts/agentscripts_test.go:50–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

48}
49
50func TestEnv(t *testing.T) {
51 t.Parallel()
52 fLogger := newFakeScriptLogger()
53 runner := setup(t, func(uuid2 uuid.UUID) agentscripts.ScriptLogger {
54 return fLogger
55 })
56 defer runner.Close()
57 id := uuid.New()
58 script := "echo $CODER_SCRIPT_DATA_DIR\necho $CODER_SCRIPT_BIN_DIR\n"
59 if runtime.GOOS == "windows" {
60 script = `
61 cmd.exe /c echo %CODER_SCRIPT_DATA_DIR%
62 cmd.exe /c echo %CODER_SCRIPT_BIN_DIR%
63 `
64 }
65 aAPI := agenttest.NewFakeAgentAPI(t, testutil.Logger(t), nil, nil)
66 err := runner.Init([]codersdk.WorkspaceAgentScript{{
67 LogSourceID: id,
68 Script: script,
69 }}, aAPI.ScriptCompleted)
70 require.NoError(t, err)
71
72 ctx := testutil.Context(t, testutil.WaitLong)
73
74 done := testutil.Go(t, func() {
75 err := runner.Execute(ctx, agentscripts.ExecuteAllScripts)
76 assert.NoError(t, err)
77 })
78 defer func() {
79 select {
80 case <-ctx.Done():
81 case <-done:
82 }
83 }()
84
85 var log []agentsdk.Log
86 for {
87 select {
88 case <-ctx.Done():
89 require.Fail(t, "timed out waiting for logs")
90 case l := <-fLogger.logs:
91 t.Logf("log: %s", l.Output)
92 log = append(log, l)
93 }
94 if len(log) >= 2 {
95 break
96 }
97 }
98 require.Contains(t, log[0].Output, filepath.Join(runner.DataDir(), id.String()))
99 require.Contains(t, log[1].Output, runner.ScriptBinDir())
100}
101
102func TestTimeout(t *testing.T) {
103 t.Parallel()

Callers

nothing calls this directly

Calls 15

NewFakeAgentAPIFunction · 0.92
LoggerFunction · 0.92
ContextFunction · 0.92
GoFunction · 0.92
newFakeScriptLoggerFunction · 0.85
DataDirMethod · 0.80
ScriptBinDirMethod · 0.80
setupFunction · 0.70
CloseMethod · 0.65
NewMethod · 0.65
InitMethod · 0.65
ExecuteMethod · 0.65

Tested by

no test coverage detected