(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestWaitForTaskSuccess(t *testing.T) { |
| 200 | const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:" |
| 201 | |
| 202 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 203 | w.Header().Set("Content-Type", "application/json") |
| 204 | |
| 205 | switch { |
| 206 | case r.URL.Path == "/api2/json/access/ticket": |
| 207 | _, _ = w.Write([]byte(authResponse)) |
| 208 | case r.URL.Path == "/api2/json/cluster/tasks": |
| 209 | // Return the task as already complete with OK status. |
| 210 | body := `{"data":[{"upid":"` + upid + `","status":"OK","endtime":1700000060,"starttime":1700000000,"node":"pve","type":"qmcreate"}]}` |
| 211 | _, _ = w.Write([]byte(body)) |
| 212 | case strings.Contains(r.URL.Path, "/tasks/") && strings.HasSuffix(r.URL.Path, "/status"): |
| 213 | _, _ = w.Write([]byte(taskStatusResponse("OK"))) |
| 214 | default: |
| 215 | http.NotFound(w, r) |
| 216 | } |
| 217 | })) |
| 218 | defer server.Close() |
| 219 | |
| 220 | client := newTestClient(t, server.URL) |
| 221 | |
| 222 | exitStatus, err := waitForTask(context.Background(), client, "pve", upid, "test-op") |
| 223 | if err != nil { |
| 224 | t.Fatalf("waitForTask returned unexpected error: %v", err) |
| 225 | } |
| 226 | |
| 227 | if exitStatus != "OK" { |
| 228 | t.Errorf("exitStatus = %q, want %q", exitStatus, "OK") |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | func TestWaitForTaskFailure(t *testing.T) { |
| 233 | const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:" |
nothing calls this directly
no test coverage detected