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

Function TestWaitForTaskFailure

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

Source from the content-addressed store, hash-verified

230}
231
232func 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
269func TestWaitForTaskCancelled(t *testing.T) {
270 const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:"

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected