| 1 | package movement |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestPlaceholdersRefuseTheCanonicalHostOnly(t *testing.T) { |
| 6 | if len(Placeholders()) == 0 { |
| 7 | t.Skip("copy review has landed; this gate has done its job") |
| 8 | } |
| 9 | |
| 10 | if err := CheckPlaceholders("https://"+CanonicalHost, CanonicalHost); err == nil { |
| 11 | t.Error("unreviewed copy must not be allowed to serve the canonical host") |
| 12 | } |
| 13 | |
| 14 | // A canary serves the same binary production would, and the shipping |
| 15 | // cadence reviews branches on a deployed canary. If placeholders refused |
| 16 | // here too, the engine could never be reviewed before copy review — which |
| 17 | // is the whole reason the copy table exists. |
| 18 | for _, origin := range []string{ |
| 19 | "https://c1." + CanonicalHost, |
| 20 | "http://127.0.0.1:8080", |
| 21 | "http://app.test", |
| 22 | } { |
| 23 | if err := CheckPlaceholders(origin, CanonicalHost); err != nil { |
| 24 | t.Errorf("%s must boot with placeholders: %v", origin, err) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestUnknownCopyIDPanics(t *testing.T) { |
| 30 | defer func() { |
| 31 | if recover() == nil { |
| 32 | t.Fatal("an unknown copy id must panic; rendering empty ships a blank page") |
| 33 | } |
| 34 | }() |
| 35 | T("no.such.id") |
| 36 | } |
| 37 | |
| 38 | // Every id the templates and handlers ask for has to exist, or T panics at |
| 39 | // render time in front of a visitor rather than here. |
| 40 | func TestEveryReferencedCopyIDResolves(t *testing.T) { |
| 41 | for _, id := range []string{ |
| 42 | "index.headline", "index.lede", |
| 43 | "sent.title", "sent.body", |
| 44 | "confirm.title", "confirm.button", "confirm.done", "confirm.dead", |
| 45 | "form.email", "form.background", "form.submit", |
| 46 | "mail.confirm.subject", "mail.confirm.body", |
| 47 | } { |
| 48 | func() { |
| 49 | defer func() { |
| 50 | if r := recover(); r != nil { |
| 51 | t.Errorf("copy id %q is referenced but missing", id) |
| 52 | } |
| 53 | }() |
| 54 | _ = T(id) |
| 55 | }() |
| 56 | } |
| 57 | } |
| 58 | |