Skip to content
quarry Artifact [513a0b19c4]
Login

Artifact [513a0b19c4]

Artifact 513a0b19c4bc405efbbd91ab6c7b549c0709e6645f87288b782a4e2929b6197a:


package web

import (
	"os"
	"strings"
	"testing"
)

// A forge-only binding draws no composer.
//
// bucket.get answers bound:true for the forge fallback, so reading
// Bound alone would offer an upload control that attachment.begin now
// refuses — the false-offer shape this forge spent a day removing, and
// it would have been introduced BY the fix for 9b8b8fb6.
//
// forge counts as unbound for the composer, and the Unbound branch was
// already the right words: an admin is told to bind one in settings,
// and a reader who cannot act is told nothing.
func TestAForgeOnlyBindingDrawsNoComposer(t *testing.T) {
	b, err := os.ReadFile("attach.go")
	if err != nil {
		t.Fatal(err)
	}
	src := string(b)
	if !strings.Contains(src, "if !v.Bound || v.Forge {") {
		t.Error("FAIL: the composer reads Bound without Forge, so a repository with only " +
			"the forge binding is offered an upload its op refuses")
	}
	if !strings.Contains(src, `Forge  bool  `+"`"+`json:"forge"`+"`"+``) {
		t.Error("FAIL: the decoded bucket answer drops the forge flag, so the check above " +
			"can never fire")
	}
}

// And the words a reader gets are the actionable ones.
func TestTheUnboundNoteNamesTheSettingsPage(t *testing.T) {
	var out strings.Builder
	c := attachCtx{Repo: "alpha", Target: "t", Write: &attachWrite{Unbound: true}}
	if err := attachFragPage.ExecuteTemplate(&out, "attachments", c); err != nil {
		t.Fatal(err)
	}
	body := out.String()
	if !strings.Contains(body, "settings#attachments") {
		t.Error("FAIL: the unbound note does not link the settings page")
	}
	if !strings.Contains(body, "No bucket is bound") {
		t.Error("FAIL: the unbound note does not say what is wrong")
	}
	// A reader who cannot bind one is told nothing they cannot act on.
	var reader strings.Builder
	rc := attachCtx{Repo: "alpha", Target: "t", Write: &attachWrite{}}
	if err := attachFragPage.ExecuteTemplate(&reader, "attachments", rc); err != nil {
		t.Fatal(err)
	}
	if strings.Contains(reader.String(), "No bucket is bound") {
		t.Error("FAIL: a reader who cannot bind a bucket is told to bind one")
	}
}