region labels: label fields on the instance, app, regions, list, routes and sidecar doors (plan 1 task 8)
TestAPIInstanceListHealthAndFilters's exact-keys list gains region_name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+283
−6
internal/console/apicli.go+2 −0internal/console/apiinstances.go+20 −2internal/console/apiinstances_test.go+4 −2internal/console/apiregions.go+5 −1internal/console/apiroutes.go+9 −0internal/console/apisidecars.go+6 −1internal/console/apitemporary.go+10 −0internal/console/regiondefault.go+3 −0internal/console/regionwire_test.go+224 −0
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index 71b461943..82ad25458 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -26,6 +26,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/caps" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/svcrole" |
| @@ -560,6 +561,7 @@ func (s *Server) echoCreatedRegion(ctx context.Context, acct *Account, name stri |
| } |
| out["region"] = s.homeRegionOut(gotRegion) |
| out["region_name"] = s.placeOf(gotRegion, cands) |
| + out["region_label"] = regionlabel.ForCode(gotRegion, s.regionHome(), s.regionNames()).Text |
| out["region_source"] = gotSource |
| out["regions_available"] = available |
| } |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index c56015417..61d46d7b8 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -42,6 +42,7 @@ import ( |
| "github.com/carlosframework/platform/internal/hostops" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/ratelimit" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| "github.com/carlosframework/platform/internal/status" |
| @@ -159,6 +160,10 @@ type instanceListRecord struct { |
| // rather than going on serving that box's last-known version as if it |
| // were current. The deploy watch does NOT read this field. |
| StagedVersion string `json:"staged_version"` |
| + // RegionName is the record's label and MovePhrase its move's phrase |
| + // (region labels spec §4), from the console's name map: no read. |
| + RegionName string `json:"region_name"` |
| + MovePhrase string `json:"move_phrase,omitempty"` |
| // Upstreams is the per-upstream probe state the box's edge currently |
| // believes for this host (status.BoxMetrics.Upstreams), joined from the |
| // same snapshots and under the same staleness rule as StagedVersion — a |
| @@ -849,6 +854,7 @@ func (s *Server) handleAPIInstanceList(w http.ResponseWriter, r *http.Request) { |
| health := s.instanceHealth(ctx, recs) |
| counts := map[string]int{} |
| matched := make([]instanceListRecord, 0, len(recs)) |
| + home, names := s.regionHome(), s.regionNames() |
| for _, rec := range recs { |
| h := health[rec.Host] |
| counts[h]++ |
| @@ -866,7 +872,9 @@ func (s *Server) handleAPIInstanceList(w http.ResponseWriter, r *http.Request) { |
| ServedBy: served[rec.Host], Gated: rec.Gate != "", DBBytes: join.dbSize(rec.Host), |
| Rollout: join.rollout(rec.Host, acct.Sqid, app), |
| UpdateReport: join.update(rec.Host, acct.Sqid, app), |
| - SettingsDefault: provision.EffectiveUpdates(rec, policy).Default()}) |
| + SettingsDefault: provision.EffectiveUpdates(rec, policy).Default(), |
| + RegionName: regionlabel.ForRecord(rec, home, names).Text, |
| + MovePhrase: regionlabel.MovePhrase(rec, home, names)}) |
| } |
| total := len(matched) |
| // provision.ListRecords returns records host-sorted and nothing above |
| @@ -942,8 +950,10 @@ func (s *Server) handleAPIInstanceGet(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusBadGateway, "could not read the instance") |
| return |
| } |
| + home, names := s.regionHome(), s.regionNames() |
| writeJSON(w, http.StatusOK, instanceGetRecord{Record: *rec, |
| - ServedBy: loadEdgesJoin(ctx, s.cfg.Releases)[host], Gated: rec.Gate != ""}) |
| + ServedBy: loadEdgesJoin(ctx, s.cfg.Releases)[host], Gated: rec.Gate != "", |
| + RegionName: regionlabel.ForRecord(*rec, home, names).Text, MovePhrase: regionlabel.MovePhrase(*rec, home, names)}) |
| } |
| // instanceGetRecord is the single-record answer: the stored record plus the |
| @@ -959,6 +969,10 @@ type instanceGetRecord struct { |
| // is always "" and omitted. Gated is what a member may know. |
| HiddenGate string `json:"gate,omitempty"` |
| Gated bool `json:"gated"` |
| + // RegionName is the record's label and MovePhrase its move's phrase |
| + // (region labels spec §4), from the console's name map: no read. |
| + RegionName string `json:"region_name"` |
| + MovePhrase string `json:"move_phrase,omitempty"` |
| } |
| // apiRecordView is a record as the write doors answer it: the whole record |
| @@ -980,6 +994,9 @@ type apiRecordView struct { |
| // part of the record. |
| RegionFrom string `json:"region_from,omitempty"` |
| RegionName string `json:"region_name,omitempty"` |
| + // RegionLabel is the record's region label (region labels spec §4), |
| + // on every create, a fleet-placed one included ("fleet <name>"). |
| + RegionLabel string `json:"region_label,omitempty"` |
| } |
| func recordView(rec provision.Record) apiRecordView { |
| @@ -1829,6 +1846,7 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| if placed == "" { |
| out.RegionName = s.placeOf(rec.Region, s.candsOrHome(ctx)) |
| } |
| + out.RegionLabel = regionlabel.ForRecord(rec, s.regionHome(), s.regionNames()).Text |
| writeJSON(w, http.StatusCreated, out) |
| } |
diff --git a/internal/console/apiinstances_test.go b/internal/console/apiinstances_test.go| index 88523c1e9..2c9c35222 100644 |
| --- a/internal/console/apiinstances_test.go |
| +++ b/internal/console/apiinstances_test.go |
| @@ -911,8 +911,10 @@ func TestAPIInstanceListHealthAndFilters(t *testing.T) { |
| // "settings_default" joined them with the update settings (plan 5): |
| // the one bit the CLI needs to tell an instance on a box that ignores |
| // settings from one that never asked for any. |
| - if !slices.Equal(extra, []string{"gated", "health", "settings_default", "staged_version"}) { |
| - t.Errorf("%s carries extra keys %v, want exactly gated, health, settings_default and staged_version", rec.Host, extra) |
| + // "region_name" joined them with the region labels (spec §4): the |
| + // record's region as a place and a code, from the cached name map. |
| + if !slices.Equal(extra, []string{"gated", "health", "region_name", "settings_default", "staged_version"}) { |
| + t.Errorf("%s carries extra keys %v, want exactly gated, health, region_name, settings_default and staged_version", rec.Host, extra) |
| } |
| } |
| } |
diff --git a/internal/console/apiregions.go b/internal/console/apiregions.go| index 2ce670b63..11654a04c 100644 |
| --- a/internal/console/apiregions.go |
| +++ b/internal/console/apiregions.go |
| @@ -3,6 +3,8 @@ package console |
| import ( |
| "net/http" |
| "sort" |
| + |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| ) |
| // The armed-regions endpoint (issue #346): one authoritative answer to |
| @@ -42,12 +44,14 @@ func (s *Server) handleAPIRegions(w http.ResponseWriter, r *http.Request) { |
| Armed bool `json:"armed"` |
| AWSRegion string `json:"aws_region,omitempty"` |
| Name string `json:"name,omitempty"` |
| + Label string `json:"label,omitempty"` |
| } |
| set, _ := armedPlacements(r.Context(), s.cfg.Releases) |
| cands := s.candsOrHome(r.Context()) |
| named := func(code string) region { |
| c, _ := findCandidate(cands, s.homeRegionIn(code)) |
| - return region{Code: code, AWSRegion: c.AWSRegion, Name: s.placeOf(s.homeRegionIn(code), cands)} |
| + return region{Code: code, AWSRegion: c.AWSRegion, Name: s.placeOf(s.homeRegionIn(code), cands), |
| + Label: regionlabel.ForCode(s.homeRegionIn(code), s.regionHome(), s.regionNames()).Text} |
| } |
| out := make([]region, 0, len(set)+1) |
| if s.cfg.HomeRegion != "" { |
diff --git a/internal/console/apiroutes.go b/internal/console/apiroutes.go| index 64206b1ee..48eeace5d 100644 |
| --- a/internal/console/apiroutes.go |
| +++ b/internal/console/apiroutes.go |
| @@ -36,6 +36,7 @@ import ( |
| "sort" |
| "time" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -61,6 +62,11 @@ type apiRoute struct { |
| Unit string `json:"unit,omitempty"` |
| Backing string `json:"backing,omitempty"` |
| Provisioned bool `json:"provisioned"` |
| + // Region is the row's placement as the CLI names it (the home's name |
| + // for the record's "") and RegionName its label (region labels spec |
| + // §4). An older console sends neither. |
| + Region string `json:"region"` |
| + RegionName string `json:"region_name,omitempty"` |
| // Replication is the rung of the replication ladder this route's |
| // database is replicated on — "" (the pre-ladder default), stream, |
| // batched or daily. Additive, omitempty: an older client decodes the |
| @@ -156,6 +162,7 @@ func (s *Server) handleAPIRoutes(w http.ResponseWriter, r *http.Request) { |
| health := s.healthByHost(ctx, routeFor, nil) |
| join := loadBoxJoin(ctx, s.cfg.Releases, time.Now()) |
| rows := make([]apiRoute, 0, len(routeFor)) |
| + home, names := s.regionHome(), s.regionNames() |
| for _, rt := range routeFor { |
| rows = append(rows, apiRoute{ |
| Host: rt.Host, Kind: rt.Kind, Upstream: routeUpstream(rt), App: rt.App, |
| @@ -164,6 +171,8 @@ func (s *Server) handleAPIRoutes(w http.ResponseWriter, r *http.Request) { |
| Backing: rt.Backing, Provisioned: rt.Provisioned, |
| Replication: rt.Replication, DBBytes: join.dbSize(rt.Host), |
| PlatformCanary: rt.Platform && rt.Canary, |
| + Region: s.homeRegionOut(rt.Region), |
| + RegionName: regionlabel.ForRoute(rt, home, names).Text, |
| }) |
| } |
| // Sorted by host: registry order is not stable across passes, and a |
diff --git a/internal/console/apisidecars.go b/internal/console/apisidecars.go| index b56d45c93..034f91f81 100644 |
| --- a/internal/console/apisidecars.go |
| +++ b/internal/console/apisidecars.go |
| @@ -51,6 +51,7 @@ import ( |
| "github.com/carlosframework/platform/internal/hostops" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -128,6 +129,8 @@ type sidecarListRecord struct { |
| // sidecar that has not started anywhere reads EMPTY and is rendered |
| // "unknown", never as the channel's desired version. |
| RunningVersion string `json:"running_version"` |
| + // RegionName is the sidecar's region label (region labels spec §4). |
| + RegionName string `json:"region_name,omitempty"` |
| } |
| // handleAPISidecarList answers `carlos sidecars ls`: this app's records, |
| @@ -148,8 +151,10 @@ func (s *Server) handleAPISidecarList(w http.ResponseWriter, r *http.Request) { |
| } |
| join := loadBoxJoin(ctx, s.cfg.Releases, time.Now()) |
| out := make([]sidecarListRecord, 0, len(recs)) |
| + home, names := s.regionHome(), s.regionNames() |
| for _, rec := range recs { |
| - out = append(out, sidecarListRecord{SidecarRecord: rec, RunningVersion: join.serving[rec.Host]}) |
| + out = append(out, sidecarListRecord{SidecarRecord: rec, RunningVersion: join.serving[rec.Host], |
| + RegionName: regionlabel.ForCode(rec.Region, home, names).Text}) |
| } |
| if s.cfg.HostClaim { |
| pending, err := s.claimPendingViews(ctx, acct.Sqid, app, "sidecar") |
diff --git a/internal/console/apitemporary.go b/internal/console/apitemporary.go| index 23166278d..7568d897c 100644 |
| --- a/internal/console/apitemporary.go |
| +++ b/internal/console/apitemporary.go |
| @@ -393,6 +393,7 @@ func (s *Server) handleAPIAppList(w http.ResponseWriter, r *http.Request) { |
| } |
| return time.Unix(unix, 0).UTC().Format(time.RFC3339) |
| } |
| + routes, routesOK := s.registryRoutes() |
| out := make([]map[string]any, 0, len(lives)) |
| for _, l := range lives { |
| if p.Kind == PrincipalService && p.App != "" && l.App != p.App { |
| @@ -402,6 +403,15 @@ func (s *Server) handleAPIAppList(w http.ResponseWriter, r *http.Request) { |
| if l.Trashed() { |
| entry["purge_after"] = effectivePurgeAt(l.DeletedAt, l.PurgeAfter).Format(time.RFC3339) |
| } |
| + // Region labels (spec §4, labels 3): the stored region or fleet from |
| + // SQLite and the one registry listing above. region_name is always |
| + // sent by this console, "" when the placement could not be read, so |
| + // a CLI can tell an unknown from an older console. |
| + f := s.regionFactsFor(acct, l.App, fleetFromRoutes(routes, acct.Sqid, l.App), routesOK) |
| + entry["region_name"] = f.Text() |
| + if f.Known { |
| + entry["region"] = f.Code() |
| + } |
| out = append(out, entry) |
| } |
| writeJSON(w, http.StatusOK, out) |
diff --git a/internal/console/regiondefault.go b/internal/console/regiondefault.go| index 053ea246d..d5c55ba66 100644 |
| --- a/internal/console/regiondefault.go |
| +++ b/internal/console/regiondefault.go |
| @@ -8,6 +8,7 @@ import ( |
| "strings" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionlabel" |
| ) |
| // appDefaultView is §9.3's app_default. region is the STORED region (what |
| @@ -20,6 +21,7 @@ import ( |
| type appDefaultView struct { |
| Region string `json:"region"` |
| Name string `json:"name"` |
| + Label string `json:"label,omitempty"` |
| Source string `json:"source"` |
| Effective string `json:"effective"` |
| Available *bool `json:"available,omitempty"` |
| @@ -48,6 +50,7 @@ func (s *Server) appDefault(ctx context.Context, acct *Account, app string) appD |
| } |
| if rerr == nil { |
| v.Region, v.Name, v.Source, v.Effective = s.homeRegionOut(stored), s.placeOf(stored, cands), source, s.homeRegionOut(stored) |
| + v.Label = regionlabel.ForCode(stored, s.regionHome(), s.regionNames()).Text |
| } |
| switch { |
| case pol.State == policyUnreadable: |
diff --git a/internal/console/regionwire_test.go b/internal/console/regionwire_test.go| new file mode 100644 |
| index 000000000..08cb6c98a |
| --- /dev/null |
| +++ b/internal/console/regionwire_test.go |
| @@ -0,0 +1,224 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "net/http" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +func decode(t *testing.T, body string, v any) { |
| + t.Helper() |
| + if err := json.Unmarshal([]byte(body), v); err != nil { |
| + t.Fatalf("%v: %s", err, body) |
| + } |
| +} |
| + |
| +func TestInstanceDoorsCarryLabels(t *testing.T) { |
| + tb := newTwoBoxes(t) |
| + tb.setUp(t, true) |
| + publishRegionEdges(t, tb) |
| + if _, err := provision.SetRecordMove(context.Background(), tb.fx.rel, tb.sqid, "shop", remoteHost, |
| + provision.OfflineStart(labelMoveID, "uk", "au", "ops@example.com", time.Now())); err != nil { |
| + t.Fatal(err) |
| + } |
| + status, _, body := rawReq(t, http.MethodGet, instancesURL(tb.fx, tb.sqid, "shop"), tb.token, "") |
| + var list struct { |
| + Instances []struct { |
| + Host, Region string |
| + RegionName string `json:"region_name"` |
| + MovePhrase string `json:"move_phrase"` |
| + } `json:"instances"` |
| + } |
| + decode(t, body, &list) |
| + got := map[string][3]string{} |
| + for _, r := range list.Instances { |
| + got[r.Host] = [3]string{r.Region, r.RegionName, r.MovePhrase} |
| + } |
| + if status != http.StatusOK || got[remoteHost] != [3]string{"uk", "London (uk)", "moving to Sydney (au)"} || |
| + got[localHost] != [3]string{"ie", "Dublin (ie)", ""} { |
| + t.Fatalf("list = %d %v", status, got) |
| + } |
| + status, _, body = rawReq(t, http.MethodGet, instancesURL(tb.fx, tb.sqid, "shop")+"/"+remoteHost, tb.token, "") |
| + var one struct { |
| + RegionName string `json:"region_name"` |
| + MovePhrase string `json:"move_phrase"` |
| + } |
| + decode(t, body, &one) |
| + if status != http.StatusOK || one.RegionName != "London (uk)" || one.MovePhrase != "moving to Sydney (au)" { |
| + t.Fatalf("get = %d %+v", status, one) |
| + } |
| + |
| + // The create door: region_name is still placeOf's (from eligible boxes |
| + // only, so here the bare code: the fixture has no secrets key), and |
| + // region_label is the name map's. |
| + status, _, body = rawReq(t, http.MethodPost, instancesURL(tb.fx, tb.sqid, "shop"), tb.token, |
| + `{"host":"uk2.shop.example.com","region":"uk"}`) |
| + var created struct { |
| + RegionName string `json:"region_name"` |
| + RegionLabel string `json:"region_label"` |
| + } |
| + decode(t, body, &created) |
| + if status != http.StatusCreated || created.RegionName == "" || created.RegionLabel != "London (uk)" { |
| + t.Fatalf("create = %d %s", status, body) |
| + } |
| +} |
| + |
| +func TestAppDoorsCarryLabels(t *testing.T) { |
| + tb := newTwoBoxes(t) |
| + tb.setUp(t, true) |
| + publishRegionEdges(t, tb) |
| + |
| + // /regions: a label per entry, and app_default's. |
| + _, res := getJSON(t, tb.fx.ts.URL+"/api/cli/apps/"+tb.sqid+"/shop/regions", tb.token) |
| + d, _ := res["app_default"].(map[string]any) |
| + if d["label"] != "Dublin (ie)" || d["region"] != "ie" { |
| + t.Fatalf("app_default = %v", d) |
| + } |
| + labels := map[string]any{} |
| + for _, e := range res["regions"].([]any) { |
| + m := e.(map[string]any) |
| + labels[m["code"].(string)] = m["label"] |
| + } |
| + if labels["ie"] != "Dublin (ie)" || labels["uk"] != "London (uk)" { |
| + t.Fatalf("regions = %v", labels) |
| + } |
| + |
| + // /new: region_label beside region_name. |
| + _, created := postJSON(t, newAppURL(tb.fx), map[string]string{"name": "cart"}, tb.token) |
| + if created["region_label"] != "Dublin (ie)" { |
| + t.Fatalf("/new = %v", created) |
| + } |
| + |
| + // routes: the console box's row for the ie instance. |
| + _, rres := getJSON(t, tb.fx.ts.URL+"/api/cli/apps/"+tb.sqid+"/shop/routes", tb.token) |
| + found := false |
| + for _, e := range rres["routes"].([]any) { |
| + m := e.(map[string]any) |
| + if m["host"] == localHost { |
| + found = m["region"] == "ie" && m["region_name"] == "Dublin (ie)" |
| + } |
| + } |
| + if !found { |
| + t.Fatalf("routes = %v", rres) |
| + } |
| +} |
| + |
| +// TestAppListCarriesStoredRegions: §4's /list, labels 3 and R3-3: SQLite |
| +// and one registry listing, whatever the number of apps; no store call. |
| +func TestAppListCarriesStoredRegions(t *testing.T) { |
| + tb := newTwoBoxes(t) |
| + tb.setUp(t, false) |
| + now := time.Now() |
| + for _, app := range []string{"blog", "legacy"} { |
| + if _, err := tb.fx.st.CreateAppIn(5151, app, "paul@keymail.dev", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + regA, _ := registry.Open(tb.fx.regPath) |
| + if err := regA.Upsert(registry.Route{Host: "legacy.shop.example.com", Kind: "instance", App: "legacy", |
| + Account: tb.sqid, Region: "fleet/private"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + publishRegionEdges(t, tb) |
| + cs := &opCountStore{Store: tb.fx.rel} // Task 4: every Store method counted |
| + tb.fx.srv.cfg.Releases = cs |
| + lists := 0 |
| + tb.fx.srv.listRoutes = func() ([]registry.Route, error) { lists++; return regA.List() } |
| + listApps := func() map[string]map[string]any { |
| + status, _, body := rawReq(t, http.MethodGet, tb.fx.ts.URL+"/api/cli/apps/"+tb.sqid+"/list", tb.token, "") |
| + var rows []map[string]any |
| + decode(t, body, &rows) |
| + if status != http.StatusOK { |
| + t.Fatalf("/list = %d %s", status, body) |
| + } |
| + out := map[string]map[string]any{} |
| + for _, r := range rows { |
| + out[r["app"].(string)] = r |
| + } |
| + return out |
| + } |
| + cs.reset() |
| + rows := listApps() |
| + if rows["shop"]["region_name"] != "Dublin (ie)" || rows["shop"]["region"] != "ie" || |
| + rows["legacy"]["region_name"] != "fleet private" || rows["legacy"]["region"] != "fleet/private" { |
| + t.Fatalf("/list = %v", rows) |
| + } |
| + if _, has := rows["shop"]["elsewhere"]; has { |
| + t.Fatal("/list carries no elsewhere counts (labels 3)") |
| + } |
| + if lists != 1 { |
| + t.Fatalf("/list listed the registry %d times for 3 apps, want once", lists) |
| + } |
| + if n := cs.total(); n != 0 { |
| + t.Fatalf("/list made %d store calls %v, want none: SQLite and the registry only", n, cs.snapshot()) |
| + } |
| + // An unreadable registry: legacy's fleet is unknown, so no region and an |
| + // empty name (a dash in the CLI), never the home. |
| + tb.fx.srv.listRoutes = func() ([]registry.Route, error) { return nil, errors.New("registry unreadable") } |
| + rows = listApps() |
| + if _, has := rows["legacy"]["region"]; has || rows["legacy"]["region_name"] != "" { |
| + t.Fatalf("unreadable registry: legacy = %v", rows["legacy"]) |
| + } |
| + // §10's GET /api/cli/apps check is Task 4's TestPlainAppListIsUnchanged, |
| + // against the base's bytes. |
| +} |
| + |
| +// TestFleetCreateCarriesItsLabel (spec §4; Astra plan finding 3): a |
| +// fleet-placed app's create answer has no region_name (the fleet is not a |
| +// platform place) but does carry region_label, "fleet <name>". |
| +func TestFleetCreateCarriesItsLabel(t *testing.T) { |
| + tb := newTwoBoxes(t) |
| + tb.setUp(t, false) |
| + publishRegionEdges(t, tb) |
| + ctx := context.Background() |
| + if _, err := tb.fx.st.CreateAppIn(5151, "cart", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := provision.PutManifest(ctx, tb.fx.rel, tb.sqid, "cart", |
| + provision.Manifest{Schema: 1, App: "cart", Domain: "cart.example.com", Channel: "stable"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := tb.fx.st.SetAppPlacement(5151, "cart", "fleet/private"); err != nil { |
| + t.Fatal(err) |
| + } |
| + code, _, body := rawReq(t, http.MethodPost, instancesURL(tb.fx, tb.sqid, "cart"), tb.token, `{"host":"a.cart.example.com"}`) |
| + var created struct { |
| + Region string `json:"region"` |
| + RegionName string `json:"region_name"` |
| + RegionLabel string `json:"region_label"` |
| + } |
| + decode(t, body, &created) |
| + if code != http.StatusCreated || created.Region != "fleet/private" || created.RegionName != "" || created.RegionLabel != "fleet private" { |
| + t.Fatalf("fleet create = %d %s", code, body) |
| + } |
| +} |
| + |
| +func TestSidecarListCarriesLabels(t *testing.T) { |
| + tb := newTwoBoxes(t) |
| + tb.setUp(t, false) |
| + publishRegionEdges(t, tb) |
| + if err := provision.PutSidecarManifest(context.Background(), tb.fx.rel, tb.sqid, "shop", provision.SidecarManifest{ |
| + Schema: 1, App: "shop", Pool: "shop", Channel: "stable", Regions: []string{"uk"}, Args: []string{"worker"}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + u := sidecarsURL(tb.fx, tb.sqid, "shop") |
| + if status, _, out := rawReq(t, http.MethodPost, u, tb.token, `{"name":"bot","region":"uk"}`); status != http.StatusCreated { |
| + t.Fatalf("create = %d %s", status, out) |
| + } |
| + _, _, body := rawReq(t, http.MethodGet, u, tb.token, "") |
| + var list struct { |
| + Sidecars []struct { |
| + RegionName string `json:"region_name"` |
| + } `json:"sidecars"` |
| + } |
| + decode(t, body, &list) |
| + if len(list.Sidecars) != 1 || list.Sidecars[0].RegionName != "London (uk)" { |
| + t.Fatalf("sidecars = %s", body) |
| + } |
| +} |