package host import ( "errors" "strings" "testing" "github.com/carlosframework/platform/internal/caps" "github.com/carlosframework/platform/internal/cgroup" "github.com/carlosframework/platform/internal/registry" "github.com/carlosframework/platform/internal/release" ) // TestMemTier: the tier is a platform choice keyed on ONE manifest bit. // Everything that isn't "declares children" — no manifest, no // capabilities block, an unreadable sibling — is the default tier: the // safe direction is the smaller cap, and the caps pass will say why the // sibling is unreadable in its own advice. func TestMemTier(t *testing.T) { rt := registry.Route{Host: "h.example.com", App: "app"} cases := []struct { name string m *release.Manifest err error want cgroup.Limit }{ {"no manifest", nil, nil, cgroup.TierDefault}, {"unreadable", nil, errors.New("boom"), cgroup.TierDefault}, {"no capabilities", &release.Manifest{}, nil, cgroup.TierDefault}, {"capabilities, no children", &release.Manifest{Capabilities: &caps.Set{V: caps.Version}}, nil, cgroup.TierDefault}, {"children", &release.Manifest{Capabilities: &caps.Set{V: caps.Version, Children: true}}, nil, cgroup.TierChildren}, } for _, c := range cases { tier := memTier(func(registry.Route) (*release.Manifest, error) { return c.m, c.err }) if got := tier(rt); got != c.want { t.Errorf("%s: tier = %v, want %v", c.name, got, c.want) } } } // memTierOf reads the NAMED version's manifest, never the live link's: a // generation's limits are its own artifact's (zero-downtime spec §7.3). func TestMemTierOfReadsTheNamedVersion(t *testing.T) { rt := registry.Route{Host: "h.example.com", App: "app"} var asked []string tier := memTierOf(func(_ registry.Route, v string) (*release.Manifest, error) { asked = append(asked, v) if v == "v1" { return &release.Manifest{Capabilities: &caps.Set{V: caps.Version, Children: true}}, nil } return &release.Manifest{}, nil }) if got := tier(rt, "v1"); got != cgroup.TierChildren { t.Errorf("v1 = %v, want the children tier", got) } if got := tier(rt, "v2"); got != cgroup.TierDefault { t.Errorf("v2 = %v, want the default tier", got) } if strings.Join(asked, ",") != "v1,v2" { t.Errorf("read the manifests of %v, want v1 then v2", asked) } }