|
7 | 7 | "io" |
8 | 8 | "net/http" |
9 | 9 | "net/http/httptest" |
10 | | - "os" |
11 | 10 | "strings" |
12 | 11 | "testing" |
13 | 12 |
|
@@ -131,92 +130,6 @@ func TestHTTPRequest_ConfiguredHeaders(t *testing.T) { |
131 | 130 | assert.Equal(t, sessionID, receivedSessionID) |
132 | 131 | } |
133 | 132 |
|
134 | | -// TestExpandDockerEnvArgs tests the Docker environment variable expansion function |
135 | | -func TestExpandDockerEnvArgs(t *testing.T) { |
136 | | - tests := []struct { |
137 | | - name string |
138 | | - args []string |
139 | | - envVars map[string]string |
140 | | - expected []string |
141 | | - }{ |
142 | | - { |
143 | | - name: "no -e flags", |
144 | | - args: []string{"run", "--rm", "image"}, |
145 | | - envVars: map[string]string{}, |
146 | | - expected: []string{"run", "--rm", "image"}, |
147 | | - }, |
148 | | - { |
149 | | - name: "expand single env variable", |
150 | | - args: []string{"run", "-e", "VAR_NAME", "image"}, |
151 | | - envVars: map[string]string{"VAR_NAME": "value1"}, |
152 | | - expected: []string{"run", "-e", "VAR_NAME=value1", "image"}, |
153 | | - }, |
154 | | - { |
155 | | - name: "expand multiple env variables", |
156 | | - args: []string{"run", "-e", "VAR1", "-e", "VAR2", "image"}, |
157 | | - envVars: map[string]string{"VAR1": "value1", "VAR2": "value2"}, |
158 | | - expected: []string{"run", "-e", "VAR1=value1", "-e", "VAR2=value2", "image"}, |
159 | | - }, |
160 | | - { |
161 | | - name: "preserve existing key=value format", |
162 | | - args: []string{"run", "-e", "VAR=predefined", "image"}, |
163 | | - envVars: map[string]string{}, |
164 | | - expected: []string{"run", "-e", "VAR=predefined", "image"}, |
165 | | - }, |
166 | | - { |
167 | | - name: "mixed: expand and preserve", |
168 | | - args: []string{"run", "-e", "VAR1", "-e", "VAR2=fixed", "image"}, |
169 | | - envVars: map[string]string{"VAR1": "value1"}, |
170 | | - expected: []string{"run", "-e", "VAR1=value1", "-e", "VAR2=fixed", "image"}, |
171 | | - }, |
172 | | - { |
173 | | - name: "undefined env variable", |
174 | | - args: []string{"run", "-e", "UNDEFINED_VAR", "image"}, |
175 | | - envVars: map[string]string{}, |
176 | | - expected: []string{"run", "-e", "UNDEFINED_VAR", "image"}, |
177 | | - }, |
178 | | - { |
179 | | - name: "empty env variable value", |
180 | | - args: []string{"run", "-e", "EMPTY_VAR", "image"}, |
181 | | - envVars: map[string]string{"EMPTY_VAR": ""}, |
182 | | - expected: []string{"run", "-e", "EMPTY_VAR=", "image"}, |
183 | | - }, |
184 | | - { |
185 | | - name: "-e at end of args (no following arg)", |
186 | | - args: []string{"run", "image", "-e"}, |
187 | | - envVars: map[string]string{}, |
188 | | - expected: []string{"run", "image", "-e"}, |
189 | | - }, |
190 | | - } |
191 | | - |
192 | | - for _, tt := range tests { |
193 | | - t.Run(tt.name, func(t *testing.T) { |
194 | | - // Set up environment variables for test |
195 | | - for k, v := range tt.envVars { |
196 | | - os.Setenv(k, v) |
197 | | - } |
198 | | - // Clean up after test |
199 | | - t.Cleanup(func() { |
200 | | - for k := range tt.envVars { |
201 | | - os.Unsetenv(k) |
202 | | - } |
203 | | - }) |
204 | | - |
205 | | - result := expandDockerEnvArgs(tt.args) |
206 | | - |
207 | | - if len(result) != len(tt.expected) { |
208 | | - t.Fatalf("Expected %d args, got %d: %v", len(tt.expected), len(result), result) |
209 | | - } |
210 | | - |
211 | | - for i := range result { |
212 | | - if result[i] != tt.expected[i] { |
213 | | - t.Errorf("Arg %d: expected '%s', got '%s'", i, tt.expected[i], result[i]) |
214 | | - } |
215 | | - } |
216 | | - }) |
217 | | - } |
218 | | -} |
219 | | - |
220 | 133 | // TestHTTPRequest_ErrorResponses tests handling of various error conditions |
221 | 134 | func TestHTTPRequest_ErrorResponses(t *testing.T) { |
222 | 135 | tests := []struct { |
|
0 commit comments