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

Commitf607b45

Browse files
committed
integration test
1 parentc37d9d0 commitf607b45

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

‎coderd/aitasks_test.go‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,25 +416,26 @@ func TestTasks(t *testing.T) {
416416
t.Run("Send",func(t*testing.T) {
417417
t.Parallel()
418418

419-
t.Run("OK",func(t*testing.T) {
419+
t.Run("IntegrationOK",func(t*testing.T) {
420420
t.Parallel()
421421

422422
client,_,api:=coderdtest.NewWithAPI(t,&coderdtest.Options{IncludeProvisionerDaemon:true})
423423
owner:=coderdtest.CreateFirstUser(t,client)
424424
userClient,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
425425

426-
// Start a fake AgentAPI that accepts POST /message with 200 OK.
426+
// Start a fake AgentAPI that accepts GET /status and POST /message.
427+
statusResponse:=`{"body":{"status":"stable"}}`
427428
srv:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
428429
ifr.Method==http.MethodGet&&r.URL.Path=="/status" {
429-
_,_=fmt.Fprintln(w,`{"body":{"status":"stable"}}`)
430+
_,_=fmt.Fprint(w,statusResponse)
430431
w.WriteHeader(http.StatusOK)
431432
return
432433
}
433434
ifr.Method==http.MethodPost&&r.URL.Path=="/message" {
434435
w.WriteHeader(http.StatusOK)
435436
return
436437
}
437-
w.WriteHeader(http.StatusOK)
438+
w.WriteHeader(http.StatusInternalServerError)
438439
}))
439440
defersrv.Close()
440441

@@ -474,19 +475,40 @@ func TestTasks(t *testing.T) {
474475
}
475476
require.NotEqual(t,uuid.Nil,sidebarAppID)
476477

477-
// Make the sidebar apphealthy for this test.
478+
// Make the sidebar appunhealthy initially.
478479
err=api.Database.UpdateWorkspaceAppHealthByID(dbauthz.AsSystemRestricted(ctx), database.UpdateWorkspaceAppHealthByIDParams{
479480
ID:sidebarAppID,
480-
Health:database.WorkspaceAppHealthHealthy,
481+
Health:database.WorkspaceAppHealthUnhealthy,
481482
})
482483
require.NoError(t,err)
483484

484-
// Send task input to the tasks sidebar app and expect 204.
485485
exp:=codersdk.NewExperimentalClient(userClient)
486486
err=exp.TaskSend(ctx,"me",ws.ID, codersdk.TaskSendRequest{
487487
Input:"Hello, Agent!",
488488
})
489+
require.Error(t,err,"wanted error due to unhealthy sidebar app")
490+
491+
// Make the sidebar app healthy.
492+
err=api.Database.UpdateWorkspaceAppHealthByID(dbauthz.AsSystemRestricted(ctx), database.UpdateWorkspaceAppHealthByIDParams{
493+
ID:sidebarAppID,
494+
Health:database.WorkspaceAppHealthHealthy,
495+
})
489496
require.NoError(t,err)
497+
498+
statusResponse=`{"body":{"status":"bad"}}`
499+
500+
err=exp.TaskSend(ctx,"me",ws.ID, codersdk.TaskSendRequest{
501+
Input:"Hello, Agent!",
502+
})
503+
require.Error(t,err,"wanted error due to bad status")
504+
505+
statusResponse=`{"body":{"status":"stable"}}`
506+
507+
// Send task input to the tasks sidebar app and expect 204.e
508+
err=exp.TaskSend(ctx,"me",ws.ID, codersdk.TaskSendRequest{
509+
Input:"Hello, Agent!",
510+
})
511+
require.NoError(t,err,"wanted no error due to healthy sidebar app and stable status")
490512
})
491513

492514
t.Run("MissingContent",func(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp