@@ -148,17 +148,23 @@ func TestFromEnv(t *testing.T) {
148
148
name string
149
149
envVars map [string ]string
150
150
expectError bool
151
+ expected * EnvConfig
151
152
}{
152
153
{
153
- name : "valid configuration" ,
154
+ name : "valid custom configuration" ,
154
155
envVars : map [string ]string {
155
156
EnvVarAuthToken : "token123" ,
156
- EnvVarMainServerURI : "http://localhost:5678 " ,
157
- EnvVarTaskBrokerServerURI : "http://localhost:5679 " ,
158
- EnvVarRunnerServerURI : "http://localhost:5680 " ,
157
+ EnvVarMainServerURI : "http://localhost:9000 " ,
158
+ EnvVarTaskBrokerServerURI : "http://localhost:9001 " ,
159
+ EnvVarRunnerServerURI : "http://localhost:9002 " ,
159
160
EnvVarIdleTimeout : "30" ,
160
161
},
161
- expectError : false ,
162
+ expected : & EnvConfig {
163
+ AuthToken : "token123" ,
164
+ MainServerURI : "http://localhost:9000" ,
165
+ TaskBrokerServerURI : "http://localhost:9001" ,
166
+ RunnerServerURI : "http://localhost:9002" ,
167
+ },
162
168
},
163
169
{
164
170
name : "missing auth token" ,
@@ -186,7 +192,12 @@ func TestFromEnv(t *testing.T) {
186
192
EnvVarTaskBrokerServerURI : "http://localhost:5679" ,
187
193
EnvVarRunnerServerURI : "http://localhost:5680" ,
188
194
},
189
- expectError : true ,
195
+ expected : & EnvConfig {
196
+ AuthToken : "token123" ,
197
+ MainServerURI : DefaultMainServerURI ,
198
+ TaskBrokerServerURI : "http://localhost:5679" ,
199
+ RunnerServerURI : "http://localhost:5680" ,
200
+ },
190
201
},
191
202
{
192
203
name : "invalid task broker server URI" ,
@@ -205,7 +216,12 @@ func TestFromEnv(t *testing.T) {
205
216
EnvVarMainServerURI : "http://localhost:5678" ,
206
217
EnvVarRunnerServerURI : "http://localhost:5680" ,
207
218
},
208
- expectError : true ,
219
+ expected : & EnvConfig {
220
+ AuthToken : "token123" ,
221
+ MainServerURI : "http://localhost:5678" ,
222
+ TaskBrokerServerURI : DefaultTaskBrokerServerURI ,
223
+ RunnerServerURI : "http://localhost:5680" ,
224
+ },
209
225
},
210
226
{
211
227
name : "invalid runner server URI" ,
@@ -224,7 +240,12 @@ func TestFromEnv(t *testing.T) {
224
240
EnvVarMainServerURI : "http://localhost:5678" ,
225
241
EnvVarTaskBrokerServerURI : "http://localhost:5679" ,
226
242
},
227
- expectError : true ,
243
+ expected : & EnvConfig {
244
+ AuthToken : "token123" ,
245
+ MainServerURI : "http://localhost:5678" ,
246
+ TaskBrokerServerURI : "http://localhost:5679" ,
247
+ RunnerServerURI : DefaultRunnerServerURI ,
248
+ },
228
249
},
229
250
{
230
251
name : "missing scheme in 127.0.0.1 URI" ,
@@ -296,20 +317,8 @@ func TestFromEnv(t *testing.T) {
296
317
return
297
318
}
298
319
299
- if envCfg .AuthToken != tt .envVars [EnvVarAuthToken ] {
300
- t .Errorf ("FromEnv() AuthToken = %v, want %v" , envCfg .AuthToken , tt .envVars [EnvVarAuthToken ])
301
- }
302
-
303
- if envCfg .MainServerURI != tt .envVars [EnvVarMainServerURI ] {
304
- t .Errorf ("FromEnv() MainServerURI = %v, want %v" , envCfg .MainServerURI , tt .envVars [EnvVarMainServerURI ])
305
- }
306
-
307
- if envCfg .TaskBrokerServerURI != tt .envVars [EnvVarTaskBrokerServerURI ] {
308
- t .Errorf ("FromEnv() TaskBrokerServerURI = %v, want %v" , envCfg .TaskBrokerServerURI , tt .envVars [EnvVarTaskBrokerServerURI ])
309
- }
310
-
311
- if envCfg .RunnerServerURI != tt .envVars [EnvVarRunnerServerURI ] {
312
- t .Errorf ("FromEnv() RunnerServerURI = %v, want %v" , envCfg .RunnerServerURI , tt .envVars [EnvVarRunnerServerURI ])
320
+ if ! reflect .DeepEqual (envCfg , tt .expected ) {
321
+ t .Errorf ("FromEnv() = %+v, want %+v" , envCfg , tt .expected )
313
322
}
314
323
315
324
if os .Getenv (EnvVarRunnerServerEnabled ) != "true" {
0 commit comments