fix: lifecycle methods need value receivers - app detail page 500 (v0.158.1)
Shipped in v0.158.0, caught live within the hour. /apps/<slug> returned 500
for EVERY app: html/template cannot call a pointer-receiver method on a
non-addressable value, and appDetailHandler passes Meta as a VALUE inside a
map[string]interface{}.
It compiled and every test passed because nothing rendered app_info - the
catalog tests used the funcmap route, which takes a value and works either
way. A template method call is only checked when the template runs.
Adds TestAppInfoRendersForEveryLifecycle with the handler's exact data shape.
This commit is contained in:
@@ -136,3 +136,61 @@ func TestAvailableAppHasNoBadgeAndKeepsInstallButton(t *testing.T) {
|
||||
t.Fatal("an available, undeployed app must still offer Telepítés")
|
||||
}
|
||||
}
|
||||
|
||||
// appInfoData mirrors appDetailHandler's data map — CRUCIALLY including `"Meta": st.Meta` as a
|
||||
// stacks.Metadata VALUE inside a map[string]interface{}, which is what the handler really does.
|
||||
// That detail is the entire point of this test: html/template cannot call a POINTER-receiver method
|
||||
// on a non-addressable value, so `{{if .Meta.IsAbandoned}}` renders fine in a unit test that passes
|
||||
// a *Metadata and 500s in production. Do not "simplify" this to a pointer.
|
||||
func appInfoData(st stacks.Stack) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"Page": "stacks", "Title": st.Meta.DisplayName,
|
||||
"Stack": &st, "Meta": st.Meta, "AppInfo": st.Meta.AppInfo,
|
||||
"HasAppInfo": st.Meta.HasAppInfo(), "EffectiveSubdomain": st.Meta.Subdomain,
|
||||
"Domain": "demo-felhom.eu",
|
||||
}
|
||||
}
|
||||
|
||||
// TestAppInfoRendersForEveryLifecycle is the regression test for a defect that SHIPPED: v0.158.0's
|
||||
// first cut used pointer receivers, so `{{if .Meta.IsAbandoned}}` failed at RENDER time with
|
||||
// "can't evaluate field IsAbandoned in type interface {}" — a 500 on EVERY app detail page,
|
||||
// abandoned or not. It compiled, and every other test passed, because nothing rendered app_info.
|
||||
//
|
||||
// A template method call is only checked when the template runs. Render the page.
|
||||
func TestAppInfoRendersForEveryLifecycle(t *testing.T) {
|
||||
for _, lc := range []string{"", "available", "hidden", "abandoned", "bogus"} {
|
||||
t.Run("lifecycle="+lc, func(t *testing.T) {
|
||||
st := lcStack("someapp", lc, true)
|
||||
st.State = stacks.StateRunning
|
||||
html := renderBackupPage(t, "app_info", appInfoData(st))
|
||||
if len(html) < 500 {
|
||||
t.Fatalf("app_info rendered only %d bytes — the page is broken", len(html))
|
||||
}
|
||||
wantNotice := lc == "abandoned"
|
||||
gotNotice := strings.Contains(html, "felhagyott a fejlesztéssel")
|
||||
if gotNotice != wantNotice {
|
||||
t.Errorf("abandoned notice present=%v, want %v (lifecycle %q)", gotNotice, wantNotice, lc)
|
||||
}
|
||||
gotBadge := strings.Contains(html, "Nem karbantartott")
|
||||
if gotBadge != wantNotice {
|
||||
t.Errorf("badge present=%v, want %v (lifecycle %q)", gotBadge, wantNotice, lc)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestAppInfoHidesInstallButtonForWithdrawnApp — the undeployed view: a withdrawn app must not offer
|
||||
// Telepítés, and an available one must.
|
||||
func TestAppInfoHidesInstallButtonForWithdrawnApp(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
lifecycle string
|
||||
wantBtn bool
|
||||
}{{"", true}, {"available", true}, {"hidden", false}, {"abandoned", false}} {
|
||||
st := lcStack("someapp", c.lifecycle, false)
|
||||
html := renderBackupPage(t, "app_info", appInfoData(st))
|
||||
got := strings.Contains(html, "Telepítés</a>")
|
||||
if got != c.wantBtn {
|
||||
t.Errorf("lifecycle %q: Telepítés button present=%v, want %v", c.lifecycle, got, c.wantBtn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user