(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func TestWaitForTaskFailure(t *testing.T) { |
| 233 | const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:" |
| 234 | |
| 235 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 236 | w.Header().Set("Content-Type", "application/json") |
| 237 | |
| 238 | switch { |
| 239 | case r.URL.Path == "/api2/json/access/ticket": |
| 240 | _, _ = w.Write([]byte(authResponse)) |
| 241 | case r.URL.Path == "/api2/json/cluster/tasks": |
| 242 | // Task finished with an error status. |
| 243 | body := `{"data":[{"upid":"` + upid + `","status":"disk full","endtime":1700000060,"starttime":1700000000,"node":"pve","type":"qmcreate"}]}` |
| 244 | _, _ = w.Write([]byte(body)) |
| 245 | case strings.Contains(r.URL.Path, "/tasks/") && strings.HasSuffix(r.URL.Path, "/status"): |
| 246 | _, _ = w.Write([]byte(taskStatusResponse("disk full"))) |
| 247 | default: |
| 248 | http.NotFound(w, r) |
| 249 | } |
| 250 | })) |
| 251 | defer server.Close() |
| 252 | |
| 253 | client := newTestClient(t, server.URL) |
| 254 | |
| 255 | exitStatus, err := waitForTask(context.Background(), client, "pve", upid, "test-op") |
| 256 | if err == nil { |
| 257 | t.Fatal("waitForTask returned nil error, expected non-nil for failed task") |
| 258 | } |
| 259 | |
| 260 | if !strings.Contains(err.Error(), "disk full") { |
| 261 | t.Errorf("error message %q does not mention failure reason", err.Error()) |
| 262 | } |
| 263 | |
| 264 | if exitStatus != "ERROR" { |
| 265 | t.Errorf("exitStatus = %q, want %q", exitStatus, "ERROR") |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | func TestWaitForTaskCancelled(t *testing.T) { |
| 270 | const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:" |
nothing calls this directly
no test coverage detected