@@ -370,6 +370,9 @@ func TestWorkspaceExternalAgentCredentials(t *testing.T) {
370
370
Bool : true ,
371
371
Valid : true ,
372
372
},
373
+ }).Resource (& proto.Resource {
374
+ Name : "test-agent" ,
375
+ Type : "coder_external_agent" ,
373
376
}).WithAgent (func (a []* proto.Agent ) []* proto.Agent {
374
377
a [0 ].Name = "test-agent"
375
378
a [0 ].OperatingSystem = "linux"
@@ -393,6 +396,9 @@ func TestWorkspaceExternalAgentCredentials(t *testing.T) {
393
396
r := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
394
397
OrganizationID : user .OrganizationID ,
395
398
OwnerID : user .UserID ,
399
+ }).Resource (& proto.Resource {
400
+ Name : "test-agent" ,
401
+ Type : "coder_external_agent" ,
396
402
}).Seed (database.WorkspaceBuild {
397
403
HasExternalAgent : sql.NullBool {
398
404
Bool : true ,
@@ -426,6 +432,9 @@ func TestWorkspaceExternalAgentCredentials(t *testing.T) {
426
432
Bool : true ,
427
433
Valid : true ,
428
434
},
435
+ }).Resource (& proto.Resource {
436
+ Name : "test-agent" ,
437
+ Type : "coder_external_agent" ,
429
438
}).WithAgent (func (a []* proto.Agent ) []* proto.Agent {
430
439
a [0 ].Name = "test-agent"
431
440
a [0 ].Auth = & proto.Agent_InstanceId {
@@ -456,4 +465,34 @@ func TestWorkspaceExternalAgentCredentials(t *testing.T) {
456
465
require .ErrorAs (t , err , & apiErr )
457
466
require .Equal (t , "Workspace does not have an external agent." , apiErr .Message )
458
467
})
468
+
469
+ t .Run ("No external agent associated with agent - should return 404" , func (t * testing.T ) {
470
+ t .Parallel ()
471
+ ctx := testutil .Context (t , testutil .WaitShort )
472
+
473
+ r := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
474
+ OrganizationID : user .OrganizationID ,
475
+ OwnerID : user .UserID ,
476
+ }).Seed (database.WorkspaceBuild {
477
+ HasExternalAgent : sql.NullBool {
478
+ Bool : true ,
479
+ Valid : true ,
480
+ },
481
+ }).Resource (& proto.Resource {
482
+ Name : "test-external-agent" ,
483
+ Type : "coder_external_agent" ,
484
+ }).WithAgent (func (a []* proto.Agent ) []* proto.Agent {
485
+ a [0 ].Name = "test-agent-no-external-agent"
486
+ a [0 ].Auth = & proto.Agent_Token {
487
+ Token : uuid .NewString (),
488
+ }
489
+ return a
490
+ }).Do ()
491
+
492
+ _ , err := client .WorkspaceExternalAgentCredentials (ctx , r .Workspace .ID , "test-agent-no-external-agent" )
493
+ require .Error (t , err )
494
+ var apiErr * codersdk.Error
495
+ require .ErrorAs (t , err , & apiErr )
496
+ require .Equal (t , "Agent 'test-agent-no-external-agent' does not have an external agent associated with it." , apiErr .Message )
497
+ })
459
498
}
0 commit comments