MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / TestWaitForTaskCancelled

Function TestWaitForTaskCancelled

internal/cli/cli_helpers_test.go:269–304  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

267}
268
269func 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
306func TestInferGuestTypeFromVolID(t *testing.T) {
307 cases := []struct {

Callers

nothing calls this directly

Calls 6

waitForTaskFunction · 0.85
HeaderMethod · 0.80
newTestClientFunction · 0.70
SetMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected