Skip to content

Commit 2687bfd

Browse files
committed
allow paralleltest
1 parent 2692e55 commit 2687bfd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

agent/agentcontainers/devcontainercli_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626
"github.com/coder/coder/v2/testutil"
2727
)
2828

29-
//nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
3029
func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) {
30+
t.Parallel()
31+
3132
testExePath, err := os.Executable()
3233
require.NoError(t, err, "get test executable path")
3334

3435
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
35-
testExecer := &testDevcontainerExecer{testExePath: testExePath}
3636

3737
//nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
3838
t.Run("Up", func(t *testing.T) {
@@ -101,14 +101,19 @@ func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) {
101101
}
102102

103103
for _, tt := range tests {
104-
//nolint:paralleltest // This test is not parallel-safe due t.Setenv.
105104
t.Run(tt.name, func(t *testing.T) {
105+
t.Parallel()
106+
106107
ctx := testutil.Context(t, testutil.WaitMedium)
107108

108-
// Set environment variables for the test helper.
109-
t.Setenv("TEST_DEVCONTAINER_WANT_ARGS", tt.wantArgs)
110-
t.Setenv("TEST_DEVCONTAINER_WANT_ERROR", fmt.Sprintf("%v", tt.wantError))
111-
t.Setenv("TEST_DEVCONTAINER_LOG_FILE", filepath.Join("testdata", "devcontainercli", "parse", tt.logFile))
109+
testExecer := &testDevcontainerExecer{
110+
testExePath: testExePath,
111+
extraEnv: []string{
112+
"TEST_DEVCONTAINER_WANT_ARGS=" + tt.wantArgs,
113+
"TEST_DEVCONTAINER_WANT_ERROR=" + fmt.Sprintf("%v", tt.wantError),
114+
"TEST_DEVCONTAINER_LOG_FILE=" + filepath.Join("testdata", "devcontainercli", "parse", tt.logFile),
115+
},
116+
}
112117

113118
dccli := agentcontainers.NewDevcontainerCLI(logger, testExecer)
114119
containerID, err := dccli.Up(ctx, tt.workspace, tt.config, tt.opts...)
@@ -127,6 +132,7 @@ func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) {
127132
// testDevcontainerExecer implements the agentexec.Execer interface for testing.
128133
type testDevcontainerExecer struct {
129134
testExePath string
135+
extraEnv []string
130136
}
131137

132138
// CommandContext returns a test binary command that simulates devcontainer responses.
@@ -148,8 +154,9 @@ func (e *testDevcontainerExecer) CommandContext(ctx context.Context, name string
148154

149155
//nolint:gosec // This is a test binary, so we don't need to worry about command injection.
150156
cmd := exec.CommandContext(ctx, e.testExePath, testArgs...)
151-
// Set this environment variable so the child process knows it's the helper.
152-
cmd.Env = append(os.Environ(), "TEST_DEVCONTAINER_WANT_HELPER_PROCESS=1")
157+
cmd.Env = append(os.Environ(), e.extraEnv...)
158+
// Set this environment va[riable so the child process knows it's the helper.
159+
cmd.Env = append(cmd.Env, "TEST_DEVCONTAINER_WANT_HELPER_PROCESS=1")
153160

154161
return cmd
155162
}

0 commit comments

Comments
 (0)