Skip to content
quarry Artifact [f5f6840d4e]
Login

Artifact [f5f6840d4e]

Artifact f5f6840d4e4a697a6b83890ccaf5cc228d01ce5a045396d2ed528fea704b5b7f:


package web

import (
	"strings"
	"testing"

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

// A deploy that lands mid-operation used to render "Something went
// wrong serving this page. The details are in the server log." — a
// 500, for a request that was fine. It is a 503 with its own words
// now, and it does NOT borrow the at-capacity wording, which would
// send the reader looking for load that is not there.
func TestARestartIsNotAFaultAndIsNotCapacity(t *testing.T) {
	var buf strings.Builder
	if err := noHooks.template(restartedPage).Execute(&buf, pageData{Title: "The forge restarted"}); err != nil {
		t.Fatal(err)
	}
	body := buf.String()
	for _, want := range []string{"restarted", "try again"} {
		if !strings.Contains(strings.ToLower(body), want) {
			t.Errorf("FAIL: the page does not say %q", want)
		}
	}
	// It must not claim more than it knows: a subprocess killed
	// part-way through may or may not have written.
	for _, overclaim := range []string{"nothing was written", "no changes were made"} {
		if strings.Contains(strings.ToLower(body), overclaim) {
			t.Errorf("FAIL: the page claims %q, which it cannot know", overclaim)
		}
	}
	// And it is not the capacity story.
	var busy strings.Builder
	if err := noHooks.template(busyPage).Execute(&busy, pageData{Title: "Busy"}); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(body, "at capacity") {
		t.Errorf("FAIL: a restart borrowed the at-capacity wording")
	}
}

// The sentinel stays a member of the class every 503 path already
// handles, so nothing downstream needs to learn a new one.
func TestStoppingIsStillAnUnavailability(t *testing.T) {
	if !strings.Contains(ops.ErrStopping.Error(), "restarting") {
		t.Errorf("FAIL: ErrStopping does not name the cause: %v", ops.ErrStopping)
	}
}