@@ -2,6 +2,7 @@ package coderd_test
2
2
3
3
import (
4
4
"context"
5
+ "database/sql"
5
6
"encoding/json"
6
7
"fmt"
7
8
"maps"
@@ -1506,39 +1507,52 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
1506
1507
t .Parallel ()
1507
1508
client , db := coderdtest .NewWithDatabase (t , nil )
1508
1509
user := coderdtest .CreateFirstUser (t , client )
1509
- apps := []* proto.App {
1510
- {
1511
- Slug : "code-server" ,
1512
- Command : "some-command" ,
1513
- Url : "http://localhost:3000" ,
1514
- Icon : "/code.svg" ,
1515
- },
1516
- {
1517
- Slug : "code-server-2" ,
1518
- DisplayName : "code-server-2" ,
1519
- Command : "some-command" ,
1520
- Url : "http://localhost:3000" ,
1521
- Icon : "/code.svg" ,
1522
- Healthcheck : & proto.Healthcheck {
1523
- Url : "http://localhost:3000" ,
1524
- Interval : 5 ,
1525
- Threshold : 6 ,
1526
- },
1527
- },
1528
- }
1510
+
1511
+ // When using WithAgent() here and setting some *proto.App instances on the agent, Do() ends up trying to insert duplicate records.
1529
1512
r := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
1530
1513
OrganizationID : user .OrganizationID ,
1531
1514
OwnerID : user .UserID ,
1532
- }).WithAgent (func (agents []* proto.Agent ) []* proto.Agent {
1533
- agents [0 ].Apps = apps
1534
- return agents
1535
1515
}).Do ()
1536
1516
1517
+ res := dbgen .WorkspaceResource (t , db , database.WorkspaceResource {JobID : r .Build .JobID })
1518
+ agent := dbgen .WorkspaceAgent (t , db , database.WorkspaceAgent {ResourceID : res .ID })
1519
+
1520
+ // It's simpler to call db.InsertWorkspaceApp directly than dbgen.WorkspaceApp because it's more terse and direct;
1521
+ // the latter sets a bunch of defaults which make this test hard.
1522
+ _ , err := db .InsertWorkspaceApp (dbauthz .AsSystemRestricted (t .Context ()), database.InsertWorkspaceAppParams {
1523
+ ID : uuid .New (),
1524
+ Slug : "code-server" ,
1525
+ AgentID : agent .ID ,
1526
+ Icon : "/code.svg" ,
1527
+ Command : sql.NullString {String : "some-command" , Valid : true },
1528
+ Url : sql.NullString {String : "http://localhost:3000" , Valid : true },
1529
+ SharingLevel : database .AppSharingLevelOwner ,
1530
+ Health : database .WorkspaceAppHealthDisabled ,
1531
+ OpenIn : database .WorkspaceAppOpenInWindow ,
1532
+ })
1533
+ require .NoError (t , err )
1534
+ _ , err = db .InsertWorkspaceApp (dbauthz .AsSystemRestricted (t .Context ()), database.InsertWorkspaceAppParams {
1535
+ ID : uuid .New (),
1536
+ Slug : "code-server-2" ,
1537
+ DisplayName : "code-server-2" ,
1538
+ AgentID : agent .ID ,
1539
+ Icon : "/code.svg" ,
1540
+ Command : sql.NullString {String : "some-command" , Valid : true },
1541
+ Url : sql.NullString {String : "http://localhost:3000" , Valid : true },
1542
+ HealthcheckInterval : 5 ,
1543
+ HealthcheckUrl : "http://localhost:3000" ,
1544
+ HealthcheckThreshold : 6 ,
1545
+ Health : database .WorkspaceAppHealthInitializing ,
1546
+ SharingLevel : database .AppSharingLevelOwner ,
1547
+ OpenIn : database .WorkspaceAppOpenInWindow ,
1548
+ })
1549
+ require .NoError (t , err )
1550
+
1537
1551
ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1538
1552
defer cancel ()
1539
1553
1540
1554
agentClient := agentsdk .New (client .URL )
1541
- agentClient .SetSessionToken (r . AgentToken )
1555
+ agentClient .SetSessionToken (agent . AuthToken . String () )
1542
1556
conn , err := agentClient .ConnectRPC (ctx )
1543
1557
require .NoError (t , err )
1544
1558
defer func () {
0 commit comments