@@ -219,6 +219,150 @@ func TestConvertResources(t *testing.T) {
219
219
}},
220
220
}},
221
221
},
222
+ "multiple-agents-multiple-apps" : {
223
+ resources : []* proto.Resource {{
224
+ Name : "dev1" ,
225
+ Type : "null_resource" ,
226
+ Agents : []* proto.Agent {{
227
+ Name : "dev1" ,
228
+ OperatingSystem : "linux" ,
229
+ Architecture : "amd64" ,
230
+ Apps : []* proto.App {
231
+ {
232
+ Slug : "app1" ,
233
+ DisplayName : "app1" ,
234
+ // Subdomain defaults to false if unspecified.
235
+ Subdomain : false ,
236
+ },
237
+ {
238
+ Slug : "app2" ,
239
+ DisplayName : "app2" ,
240
+ Subdomain : true ,
241
+ Healthcheck : & proto.Healthcheck {
242
+ Url : "http://localhost:13337/healthz" ,
243
+ Interval : 5 ,
244
+ Threshold : 6 ,
245
+ },
246
+ },
247
+ },
248
+ Auth : & proto.Agent_Token {},
249
+ ConnectionTimeoutSeconds : 120 ,
250
+ DisplayApps : & displayApps ,
251
+ }},
252
+ }, {
253
+ Name : "dev2" ,
254
+ Type : "null_resource" ,
255
+ Agents : []* proto.Agent {{
256
+ Name : "dev2" ,
257
+ OperatingSystem : "linux" ,
258
+ Architecture : "amd64" ,
259
+ Apps : []* proto.App {
260
+ {
261
+ Slug : "app3" ,
262
+ DisplayName : "app3" ,
263
+ Subdomain : false ,
264
+ },
265
+ },
266
+ Auth : & proto.Agent_Token {},
267
+ ConnectionTimeoutSeconds : 120 ,
268
+ DisplayApps : & displayApps ,
269
+ }},
270
+ }},
271
+ },
272
+ "multiple-agents-multiple-envs" : {
273
+ resources : []* proto.Resource {{
274
+ Name : "dev1" ,
275
+ Type : "null_resource" ,
276
+ Agents : []* proto.Agent {{
277
+ Name : "dev1" ,
278
+ OperatingSystem : "linux" ,
279
+ Architecture : "amd64" ,
280
+ ExtraEnvs : []* proto.Env {
281
+ {
282
+ Name : "ENV_1" ,
283
+ Value : "Env 1" ,
284
+ },
285
+ {
286
+ Name : "ENV_2" ,
287
+ Value : "Env 2" ,
288
+ },
289
+ },
290
+ Auth : & proto.Agent_Token {},
291
+ ConnectionTimeoutSeconds : 120 ,
292
+ DisplayApps : & displayApps ,
293
+ }},
294
+ }, {
295
+ Name : "dev2" ,
296
+ Type : "null_resource" ,
297
+ Agents : []* proto.Agent {{
298
+ Name : "dev2" ,
299
+ OperatingSystem : "linux" ,
300
+ Architecture : "amd64" ,
301
+ ExtraEnvs : []* proto.Env {
302
+ {
303
+ Name : "ENV_3" ,
304
+ Value : "Env 3" ,
305
+ },
306
+ },
307
+ Auth : & proto.Agent_Token {},
308
+ ConnectionTimeoutSeconds : 120 ,
309
+ DisplayApps : & displayApps ,
310
+ }},
311
+ }, {
312
+ Name : "env1" ,
313
+ Type : "coder_env" ,
314
+ }, {
315
+ Name : "env2" ,
316
+ Type : "coder_env" ,
317
+ }, {
318
+ Name : "env3" ,
319
+ Type : "coder_env" ,
320
+ }},
321
+ },
322
+ "multiple-agents-multiple-scripts" : {
323
+ resources : []* proto.Resource {{
324
+ Name : "dev1" ,
325
+ Type : "null_resource" ,
326
+ Agents : []* proto.Agent {{
327
+ Name : "dev1" ,
328
+ OperatingSystem : "linux" ,
329
+ Architecture : "amd64" ,
330
+ Scripts : []* proto.Script {
331
+ {
332
+ DisplayName : "Foobar Script 1" ,
333
+ Script : "echo foobar 1" ,
334
+ RunOnStart : true ,
335
+ },
336
+ {
337
+ DisplayName : "Foobar Script 2" ,
338
+ Script : "echo foobar 2" ,
339
+ RunOnStart : true ,
340
+ },
341
+ },
342
+ Auth : & proto.Agent_Token {},
343
+ ConnectionTimeoutSeconds : 120 ,
344
+ DisplayApps : & displayApps ,
345
+ }},
346
+ }, {
347
+ Name : "dev2" ,
348
+ Type : "null_resource" ,
349
+ Agents : []* proto.Agent {{
350
+ Name : "dev2" ,
351
+ OperatingSystem : "linux" ,
352
+ Architecture : "amd64" ,
353
+ Scripts : []* proto.Script {
354
+ {
355
+ DisplayName : "Foobar Script 3" ,
356
+ Script : "echo foobar 3" ,
357
+ RunOnStart : true ,
358
+ },
359
+ },
360
+ Auth : & proto.Agent_Token {},
361
+ ConnectionTimeoutSeconds : 120 ,
362
+ DisplayApps : & displayApps ,
363
+ }},
364
+ }},
365
+ },
222
366
// Tests fetching metadata about workspace resources.
223
367
"resource-metadata" : {
224
368
resources : []* proto.Resource {{
@@ -565,6 +709,18 @@ func TestConvertResources(t *testing.T) {
565
709
sortResources (state .Resources )
566
710
sortExternalAuthProviders (state .ExternalAuthProviders )
567
711
712
+ for _ , resource := range state .Resources {
713
+ for _ , agent := range resource .Agents {
714
+ agent .Id = ""
715
+ if agent .GetToken () != "" {
716
+ agent .Auth = & proto.Agent_Token {}
717
+ }
718
+ if agent .GetInstanceId () != "" {
719
+ agent .Auth = & proto.Agent_InstanceId {}
720
+ }
721
+ }
722
+ }
723
+
568
724
expectedNoMetadata := make ([]* proto.Resource , 0 )
569
725
for _ , resource := range expected .resources {
570
726
resourceCopy , _ := protobuf .Clone (resource ).(* proto.Resource )
@@ -642,7 +798,6 @@ func TestConvertResources(t *testing.T) {
642
798
var resourcesMap []map [string ]interface {}
643
799
err = json .Unmarshal (data , & resourcesMap )
644
800
require .NoError (t , err )
645
-
646
801
require .Equal (t , expectedMap , resourcesMap )
647
802
require .ElementsMatch (t , expected .externalAuthProviders , state .ExternalAuthProviders )
648
803
})
@@ -911,6 +1066,12 @@ func sortResources(resources []*proto.Resource) {
911
1066
sort .Slice (agent .Apps , func (i , j int ) bool {
912
1067
return agent .Apps [i ].Slug < agent .Apps [j ].Slug
913
1068
})
1069
+ sort .Slice (agent .ExtraEnvs , func (i , j int ) bool {
1070
+ return agent .ExtraEnvs [i ].Name < agent .ExtraEnvs [j ].Name
1071
+ })
1072
+ sort .Slice (agent .Scripts , func (i , j int ) bool {
1073
+ return agent .Scripts [i ].DisplayName < agent .Scripts [j ].DisplayName
1074
+ })
914
1075
}
915
1076
sort .Slice (resource .Agents , func (i , j int ) bool {
916
1077
return resource .Agents [i ].Name < resource .Agents [j ].Name
0 commit comments