MCPcopy Index your code
hub / github.com/coder/coder / TestListProcesses

Function TestListProcesses

agent/agentproc/api_test.go:476–713  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

474}
475
476func TestListProcesses(t *testing.T) {
477 t.Parallel()
478
479 t.Run("NoProcesses", func(t *testing.T) {
480 t.Parallel()
481
482 handler := newTestAPI(t)
483 w := getList(t, handler)
484 require.Equal(t, http.StatusOK, w.Code)
485
486 var resp workspacesdk.ListProcessesResponse
487 err := json.NewDecoder(w.Body).Decode(&resp)
488 require.NoError(t, err)
489 require.NotNil(t, resp.Processes)
490 require.Empty(t, resp.Processes)
491 })
492
493 t.Run("FilterByChatID", func(t *testing.T) {
494 t.Parallel()
495
496 handler := newTestAPI(t)
497
498 chatA := uuid.New().String()
499 chatB := uuid.New().String()
500 headersA := http.Header{workspacesdk.CoderChatIDHeader: {chatA}}
501 headersB := http.Header{workspacesdk.CoderChatIDHeader: {chatB}}
502
503 // Start processes with different chat IDs.
504 id1 := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
505 Command: "echo chat-a",
506 }, headersA)
507 waitForExit(t, handler, id1)
508
509 id2 := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
510 Command: "echo chat-b",
511 }, headersB)
512 waitForExit(t, handler, id2)
513
514 id3 := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
515 Command: "echo chat-a-2",
516 }, headersA)
517 waitForExit(t, handler, id3)
518
519 // List with chat A header should return 2 processes.
520 w := getListWithChatHeader(t, handler, chatA)
521 require.Equal(t, http.StatusOK, w.Code)
522
523 var resp workspacesdk.ListProcessesResponse
524 err := json.NewDecoder(w.Body).Decode(&resp)
525 require.NoError(t, err)
526 require.Len(t, resp.Processes, 2)
527
528 ids := make(map[string]bool)
529 for _, p := range resp.Processes {
530 ids[p.ID] = true
531 }
532 require.True(t, ids[id1])
533 require.True(t, ids[id3])

Callers

nothing calls this directly

Calls 12

getListFunction · 0.85
startAndGetIDFunction · 0.85
waitForExitFunction · 0.85
getListWithChatHeaderFunction · 0.85
postSignalFunction · 0.85
newTestAPIFunction · 0.70
RunMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
EmptyMethod · 0.45
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected