@@ -26,13 +26,13 @@ import (
26
26
"github.com/coder/coder/v2/testutil"
27
27
)
28
28
29
- //nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
30
29
func TestDevcontainerCLI_ArgsAndParsing (t * testing.T ) {
30
+ t .Parallel ()
31
+
31
32
testExePath , err := os .Executable ()
32
33
require .NoError (t , err , "get test executable path" )
33
34
34
35
logger := slogtest .Make (t , & slogtest.Options {IgnoreErrors : true }).Leveled (slog .LevelDebug )
35
- testExecer := & testDevcontainerExecer {testExePath : testExePath }
36
36
37
37
//nolint:paralleltest // This test is not parallel-safe due to t.Setenv.
38
38
t .Run ("Up" , func (t * testing.T ) {
@@ -101,14 +101,19 @@ func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) {
101
101
}
102
102
103
103
for _ , tt := range tests {
104
- //nolint:paralleltest // This test is not parallel-safe due t.Setenv.
105
104
t .Run (tt .name , func (t * testing.T ) {
105
+ t .Parallel ()
106
+
106
107
ctx := testutil .Context (t , testutil .WaitMedium )
107
108
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
+ }
112
117
113
118
dccli := agentcontainers .NewDevcontainerCLI (logger , testExecer )
114
119
containerID , err := dccli .Up (ctx , tt .workspace , tt .config , tt .opts ... )
@@ -127,6 +132,7 @@ func TestDevcontainerCLI_ArgsAndParsing(t *testing.T) {
127
132
// testDevcontainerExecer implements the agentexec.Execer interface for testing.
128
133
type testDevcontainerExecer struct {
129
134
testExePath string
135
+ extraEnv []string
130
136
}
131
137
132
138
// CommandContext returns a test binary command that simulates devcontainer responses.
@@ -148,8 +154,9 @@ func (e *testDevcontainerExecer) CommandContext(ctx context.Context, name string
148
154
149
155
//nolint:gosec // This is a test binary, so we don't need to worry about command injection.
150
156
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" )
153
160
154
161
return cmd
155
162
}
0 commit comments