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

Function TestWaitForTaskSuccess

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

Source from the content-addressed store, hash-verified

197}
198
199func 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
232func TestWaitForTaskFailure(t *testing.T) {
233 const upid = "UPID:pve:00001234:00000000:test:qmcreate:100:user@pam:"

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected