(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func 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 |
| 52 | 0s 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"}, |
nothing calls this directly
no test coverage detected