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

Function Test_TaskStatus

cli/task_status_test.go:25–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func Test_TaskStatus(t *testing.T) {
26 t.Parallel()
27
28 for _, tc := range []struct {
29 args []string
30 expectOutput string
31 expectError string
32 hf func(context.Context, quartz.Clock) func(http.ResponseWriter, *http.Request)
33 }{
34 {
35 args: []string{"doesnotexist"},
36 expectError: httpapi.ResourceNotFoundResponse.Message,
37 hf: func(ctx context.Context, _ quartz.Clock) func(w http.ResponseWriter, r *http.Request) {
38 return func(w http.ResponseWriter, r *http.Request) {
39 switch r.URL.Path {
40 case "/api/v2/tasks/me/doesnotexist":
41 httpapi.ResourceNotFound(w)
42 return
43 default:
44 t.Errorf("unexpected path: %s", r.URL.Path)
45 }
46 }
47 },
48 },
49 {
50 args: []string{"exists"},
51 expectOutput: `STATE CHANGED STATUS HEALTHY STATE MESSAGE
520s ago active true working Thinking furiously...`,
53 hf: func(ctx context.Context, clk quartz.Clock) func(w http.ResponseWriter, r *http.Request) {
54 now := clk.Now()
55 return func(w http.ResponseWriter, r *http.Request) {
56 switch r.URL.Path {
57 case "/api/v2/tasks/me/exists":
58 httpapi.Write(ctx, w, http.StatusOK, codersdk.Task{
59 ID: uuid.MustParse("11111111-1111-1111-1111-111111111111"),
60 WorkspaceStatus: codersdk.WorkspaceStatusRunning,
61 CreatedAt: now,
62 UpdatedAt: now,
63 CurrentState: &codersdk.TaskStateEntry{
64 State: codersdk.TaskStateWorking,
65 Timestamp: now,
66 Message: "Thinking furiously...",
67 },
68 WorkspaceAgentHealth: &codersdk.WorkspaceAgentHealth{
69 Healthy: true,
70 },
71 WorkspaceAgentLifecycle: ptr.Ref(codersdk.WorkspaceAgentLifecycleReady),
72 Status: codersdk.TaskStatusActive,
73 })
74 return
75 default:
76 t.Errorf("unexpected path: %s", r.URL.Path)
77 }
78 }
79 },
80 },
81 {
82 args: []string{"exists", "--watch"},

Callers

nothing calls this directly

Calls 15

ResourceNotFoundFunction · 0.92
WriteFunction · 0.92
RefFunction · 0.92
InternalServerErrorFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
MustURLFunction · 0.92
NewWithClockFunction · 0.92
SetupConfigFunction · 0.92
tableDiffFunction · 0.85
WithContextMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected