(t *testing.T)
| 267 | } |
| 268 | |
| 269 | func TestWaitForTaskCancelled(t *testing.T) { |
| 270 | const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:" |
| 271 | |
| 272 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 273 | w.Header().Set("Content-Type", "application/json") |
| 274 | |
| 275 | if r.URL.Path == "/api2/json/access/ticket" { |
| 276 | _, _ = w.Write([]byte(authResponse)) |
| 277 | return |
| 278 | } |
| 279 | |
| 280 | // Never complete the task — return an empty task list so |
| 281 | // WaitForTaskCompletion keeps polling. |
| 282 | if r.URL.Path == "/api2/json/cluster/tasks" { |
| 283 | _, _ = w.Write([]byte(`{"data":[]}`)) |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | http.NotFound(w, r) |
| 288 | })) |
| 289 | defer server.Close() |
| 290 | |
| 291 | client := newTestClient(t, server.URL) |
| 292 | |
| 293 | ctx, cancel := context.WithCancel(context.Background()) |
| 294 | cancel() // cancelled before waitForTask is called |
| 295 | |
| 296 | _, err := waitForTask(ctx, client, "pve", upid, "test-op") |
| 297 | if err == nil { |
| 298 | t.Fatal("waitForTask returned nil error, expected cancellation error") |
| 299 | } |
| 300 | |
| 301 | if !strings.Contains(err.Error(), "cancelled") { |
| 302 | t.Errorf("error %q does not mention cancellation", err.Error()) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | func TestInferGuestTypeFromVolID(t *testing.T) { |
| 307 | cases := []struct { |
nothing calls this directly
no test coverage detected