| index ef45cb603..a4c35aa67 100644 |
| --- a/internal/console/regiondefault_test.go |
| +++ b/internal/console/regiondefault_test.go |
| @@ -4,6 +4,8 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| + "html" |
| "io" |
| "net/http" |
| "strings" |
| @@ -346,3 +348,93 @@ func TestRegionsLegacyFieldsGolden(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// C7 only when the default is CONFIRMED available; C8 whenever it is |
| +// confirmed unavailable; nothing for fleet, pooled, or a default that |
| +// could not be read (codex plan-R1 14). Assertions compare the HTML-escaped |
| +// copy, both ways (codex plan-R1 8). |
| +func TestInstancesTabRegionLines(t *testing.T) { |
| + starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, ukPlace)) |
| + cantUK := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, "uk")) |
| + page := func(fx *consoleFixture) string { |
| + _, _, body := get(t, signInPaul(t, fx), fx.u("/apps/titogo/instances")) |
| + return body |
| + } |
| + anyLine := func(body string) bool { return strings.Contains(body, `id="app-region-line"`) } |
| + |
| + fx, _, _ := fillFixture(t, "uk") |
| + fx.srv.cfg.AppRegions = true |
| + body := page(fx) |
| + if !strings.Contains(body, starts) { |
| + t.Fatal("no C7 line for an available region") |
| + } |
| + if strings.Contains(body, `id="app-region-line" class="banner error"`) { |
| + t.Error("C7 carries the warning class") |
| + } |
| + fx.rel.Delete(t.Context(), "control/edges/uk-box.json") |
| + // No box publishes uk, so its place falls back to the bare code (§14). |
| + body = page(fx) |
| + if !strings.Contains(body, cantUK) || strings.Contains(body, starts) { |
| + t.Fatal("want C8, not C7, when the region is absent (codex 7)") |
| + } |
| + if !strings.Contains(body, `id="app-region-line" class="banner error"`) { |
| + t.Error("C8 lacks the warning class") |
| + } |
| + |
| + for _, setup := range []func(*consoleFixture){ |
| + func(fx *consoleFixture) { fx.st.SetAppPlacement(OpsAccountID, "titogo", "fleet/acme") }, |
| + func(fx *consoleFixture) { |
| + m := titoManifest() |
| + m.Pool = "tito" |
| + enableInstances(t, fx, "titogo", m) |
| + }, |
| + func(fx *consoleFixture) { corruptManifest(t, fx) }, |
| + func(fx *consoleFixture) { fx.srv.cfg.Releases = failingList{fx.rel} }, |
| + // the stored region could not be read: never claimed available. |
| + func(fx *consoleFixture) { |
| + fx.srv.appRegionOf = func(int64, string) (string, string, error) { return "", "", errors.New("db gone") } |
| + }, |
| + } { |
| + fx, _, _ := fillFixture(t, "uk") |
| + setup(fx) |
| + if anyLine(page(fx)) { |
| + t.Error("a fleet, pooled or unreadable default showed a region line") |
| + } |
| + } |
| +} |
| + |
| +// PF9, PF10: an app whose region is the home (stored "", the record |
| +// vocabulary's home) gets C7 only when the home has a sibling to be told |
| +// apart from (two eligible regions); alone it says nothing. A home the |
| +// allow-list leaves out is still C8, whatever the sibling count. |
| +func TestInstancesTabRegionLineForAHomeApp(t *testing.T) { |
| + homePlace := geo.PlaceName("eu-west-1", "ie") |
| + starts := html.EscapeString(fmt.Sprintf(regionCopy.StartsIn, homePlace)) |
| + cantHome := html.EscapeString(fmt.Sprintf(regionCopy.CantStart, homePlace)) |
| + page := func(fx *consoleFixture) string { |
| + _, _, body := get(t, signInPaul(t, fx), fx.u("/apps/titogo/instances")) |
| + return body |
| + } |
| + |
| + fx, _, _ := fillFixture(t, "") |
| + if body := page(fx); !strings.Contains(body, starts) { |
| + t.Errorf("two eligible regions: want C7 naming the home %q", homePlace) |
| + } |
| + |
| + // Only the home is left: nothing to distinguish it from. |
| + fx, _, _ = fillFixture(t, "") |
| + fx.rel.Delete(t.Context(), "control/edges/uk-box.json") |
| + if body := page(fx); strings.Contains(body, `id="app-region-line"`) { |
| + t.Error("one eligible region: a region line showed") |
| + } |
| + |
| + fx, _, _ = fillFixture(t, "") |
| + m := titoManifest() |
| + m.Pool, m.Regions = "", []string{"uk"} |
| + enableInstances(t, fx, "titogo", m) |
| + body := page(fx) |
| + if !strings.Contains(body, cantHome) || strings.Contains(body, starts) || |
| + !strings.Contains(body, `id="app-region-line" class="banner error"`) { |
| + t.Error("home left out of the allow-list: want C8 only") |
| + } |
| +} |