Skip to content
quarry Artifact [254635f2a0]
Login

Artifact [254635f2a0]

Artifact 254635f2a03b3d3784d0f02f616c9b33d9d84ee32a7a668637229da277eeedcd:


package web

import (
	"fmt"
	"strings"
	"testing"

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

// An unavailable that names its reason is shown in its own words, not
// as the capacity page: a Git mirror whose default branch zit could not
// name was a "Busy, try shortly" page that never cleared (lou on Saur0n,
// 2026-10-31). A bare unavailable keeps the capacity page.
func TestANamedUnavailableIsNotBusy(t *testing.T) {
	named := fmt.Errorf("tree: %w", &ops.Refusal{Code: "mirror_head_unknown", Class: ops.ErrUnavailable,
		Message: "this mirror's default branch is unknown until its next good import"})
	if refusalCode(named) != "mirror_head_unknown" || !strings.Contains(refusalOf(named), "next good import") {
		t.Fatalf("FAIL: the refusal's code or words were lost: %q %q", refusalCode(named), refusalOf(named))
	}
	if refusalCode(ops.ErrUnavailable) != "" {
		t.Fatal("FAIL: a bare unavailable claims a reason")
	}
	var buf strings.Builder
	if err := noHooks.template(unavailablePage).Execute(&buf, pageData{Title: "Not available", Error: refusalOf(named), Repo: "demo"}); err != nil {
		t.Fatal(err)
	}
	body := buf.String()
	if !strings.Contains(body, `data-hook="unavailable"`) || !strings.Contains(body, "next good import") ||
		!strings.Contains(body, "/timeline") || strings.Contains(body, "at capacity") {
		t.Errorf("FAIL: the page does not say why, or borrows the capacity story:\n%s", body)
	}
}