Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8aef94a

Browse files
committed
chore: fix TestWorkspaceAgentAppHealth test after agent ID field now required
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent47ea9b2 commit8aef94a

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

‎coderd/agentapi/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *AppsAPI) BatchUpdateAppHealths(ctx context.Context, req *agentproto.Bat
9292
Health:app.Health,
9393
})
9494
iferr!=nil {
95-
returnnil,xerrors.Errorf("update workspace app health for app %q (%q): %w",err,app.ID,app.Slug)
95+
returnnil,xerrors.Errorf("update workspace app health for app %q (%q): %w",app.ID,app.Slug,err)
9696
}
9797
}
9898

‎coderd/workspaceagents_test.go

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd_test
22

33
import (
44
"context"
5+
"database/sql"
56
"encoding/json"
67
"fmt"
78
"maps"
@@ -1508,39 +1509,52 @@ func TestWorkspaceAgentAppHealth(t *testing.T) {
15081509
t.Parallel()
15091510
client,db:=coderdtest.NewWithDatabase(t,nil)
15101511
user:=coderdtest.CreateFirstUser(t,client)
1511-
apps:= []*proto.App{
1512-
{
1513-
Slug:"code-server",
1514-
Command:"some-command",
1515-
Url:"http://localhost:3000",
1516-
Icon:"/code.svg",
1517-
},
1518-
{
1519-
Slug:"code-server-2",
1520-
DisplayName:"code-server-2",
1521-
Command:"some-command",
1522-
Url:"http://localhost:3000",
1523-
Icon:"/code.svg",
1524-
Healthcheck:&proto.Healthcheck{
1525-
Url:"http://localhost:3000",
1526-
Interval:5,
1527-
Threshold:6,
1528-
},
1529-
},
1530-
}
1512+
1513+
// When using WithAgent() here and setting some *proto.App instances on the agent, Do() ends up trying to insert duplicate records.
15311514
r:=dbfake.WorkspaceBuild(t,db, database.WorkspaceTable{
15321515
OrganizationID:user.OrganizationID,
15331516
OwnerID:user.UserID,
1534-
}).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
1535-
agents[0].Apps=apps
1536-
returnagents
15371517
}).Do()
15381518

1519+
res:=dbgen.WorkspaceResource(t,db, database.WorkspaceResource{JobID:r.Build.JobID})
1520+
agent:=dbgen.WorkspaceAgent(t,db, database.WorkspaceAgent{ResourceID:res.ID})
1521+
1522+
// It's simpler to call db.InsertWorkspaceApp directly than dbgen.WorkspaceApp because it's more terse and direct;
1523+
// the latter sets a bunch of defaults which make this test hard.
1524+
_,err:=db.InsertWorkspaceApp(dbauthz.AsSystemRestricted(t.Context()), database.InsertWorkspaceAppParams{
1525+
ID:uuid.New(),
1526+
Slug:"code-server",
1527+
AgentID:agent.ID,
1528+
Icon:"/code.svg",
1529+
Command: sql.NullString{String:"some-command",Valid:true},
1530+
Url: sql.NullString{String:"http://localhost:3000",Valid:true},
1531+
SharingLevel:database.AppSharingLevelOwner,
1532+
Health:database.WorkspaceAppHealthDisabled,
1533+
OpenIn:database.WorkspaceAppOpenInWindow,
1534+
})
1535+
require.NoError(t,err)
1536+
_,err=db.InsertWorkspaceApp(dbauthz.AsSystemRestricted(t.Context()), database.InsertWorkspaceAppParams{
1537+
ID:uuid.New(),
1538+
Slug:"code-server-2",
1539+
DisplayName:"code-server-2",
1540+
AgentID:agent.ID,
1541+
Icon:"/code.svg",
1542+
Command: sql.NullString{String:"some-command",Valid:true},
1543+
Url: sql.NullString{String:"http://localhost:3000",Valid:true},
1544+
HealthcheckInterval:5,
1545+
HealthcheckUrl:"http://localhost:3000",
1546+
HealthcheckThreshold:6,
1547+
Health:database.WorkspaceAppHealthInitializing,
1548+
SharingLevel:database.AppSharingLevelOwner,
1549+
OpenIn:database.WorkspaceAppOpenInWindow,
1550+
})
1551+
require.NoError(t,err)
1552+
15391553
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
15401554
defercancel()
15411555

15421556
agentClient:=agentsdk.New(client.URL)
1543-
agentClient.SetSessionToken(r.AgentToken)
1557+
agentClient.SetSessionToken(agent.AuthToken.String())
15441558
conn,err:=agentClient.ConnectRPC(ctx)
15451559
require.NoError(t,err)
15461560
deferfunc() {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp