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

Function TestProcessOutput

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

Source from the content-addressed store, hash-verified

730}
731
732func TestProcessOutput(t *testing.T) {
733 t.Parallel()
734
735 t.Run("ExitedProcess", func(t *testing.T) {
736 t.Parallel()
737
738 handler := newTestAPI(t)
739
740 id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
741 Command: "echo hello-output",
742 })
743
744 resp := waitForExit(t, handler, id)
745 require.False(t, resp.Running)
746 require.NotNil(t, resp.ExitCode)
747 require.Equal(t, 0, *resp.ExitCode)
748 require.Contains(t, resp.Output, "hello-output")
749 })
750
751 t.Run("RunningProcess", func(t *testing.T) {
752 t.Parallel()
753
754 handler := newTestAPI(t)
755
756 id := startAndGetID(t, handler, workspacesdk.StartProcessRequest{
757 Command: "sleep 300",
758 Background: true,
759 })
760
761 w := getOutput(t, handler, id)
762 require.Equal(t, http.StatusOK, w.Code)
763
764 var resp workspacesdk.ProcessOutputResponse
765 err := json.NewDecoder(w.Body).Decode(&resp)
766 require.NoError(t, err)
767 require.True(t, resp.Running)
768
769 // Kill and wait for the process so cleanup does
770 // not hang.
771 postSignal(
772 t, handler, id,
773 workspacesdk.SignalProcessRequest{Signal: "kill"},
774 )
775 waitForExit(t, handler, id)
776 })
777
778 t.Run("NonexistentProcess", func(t *testing.T) {
779 t.Parallel()
780
781 handler := newTestAPI(t)
782 w := getOutput(t, handler, "nonexistent-id-12345")
783 require.Equal(t, http.StatusNotFound, w.Code)
784
785 var resp codersdk.Response
786 err := json.NewDecoder(w.Body).Decode(&resp)
787 require.NoError(t, err)
788 require.Contains(t, resp.Message, "not found")
789 })

Callers

nothing calls this directly

Calls 15

startAndGetIDFunction · 0.85
waitForExitFunction · 0.85
getOutputFunction · 0.85
postSignalFunction · 0.85
getOutputWithHeadersFunction · 0.85
getOutputWithWaitFunction · 0.85
getOutputWithWaitCtxFunction · 0.85
newTestAPIFunction · 0.70
RunMethod · 0.65
NewMethod · 0.65
AddMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected