Skip to content
quarry Artifact [7494684d27]
Login

Artifact [7494684d27]

Artifact 7494684d273b2a1e2a04fef28152f534cd82124632c7b38276ec35a145eea04a:


package api

import (
	"context"
	"encoding/json"
	"testing"

	"craftdesign.group/quarry/internal/ops"
	"craftdesign.group/quarry/internal/zitcli"
)

// The ops status carries the maintenance tasks the composition root
// reports, under the literal key the page decodes.
func TestOpsStatusCarriesTheMaintenanceTasks(t *testing.T) {
	d := Deps{Version: "v", Repos: NewRepos(map[string]*Repo{}),
		Maintenance: func() []zitcli.MaintTask {
			return []zitcli.MaintTask{{Store: "tcl", Task: "file history", State: "waiting",
				WaitingOn: []string{"deploy running"}, AgeMs: 5}}
		}}
	r := ops.NewRegistry()
	if err := RegisterAll(r, d); err != nil {
		t.Fatal(err)
	}
	got, err := r.Invoke(ops.WithUser(context.Background(), "dan"), "ops.status", opsStatusIn{})
	if err != nil {
		t.Fatal(err)
	}
	raw, _ := json.Marshal(got)
	var wire struct {
		Maintenance []map[string]any `json:"maintenance"`
	}
	if err := json.Unmarshal(raw, &wire); err != nil {
		t.Fatal(err)
	}
	if len(wire.Maintenance) != 1 {
		t.Fatalf("FAIL: %d maintenance rows on the wire, want 1: %s", len(wire.Maintenance), raw)
	}
	m := wire.Maintenance[0]
	if m["store"] != "tcl" || m["task"] != "file history" || m["state"] != "waiting" || m["waitingOn"] == nil {
		t.Errorf("FAIL: the maintenance row reads %v", m)
	}
	if !t.Failed() {
		t.Log("ok")
	}
}