package main import ( "testing" "github.com/novox/mesh-controller/internal/catalogue" "github.com/novox/mesh-controller/internal/inventory" "github.com/novox/mesh-controller/internal/link" ) // **A change plan says its class** (novox/hq ADR 0313 ยง2): the issue tracker holds a fix to the budget of the // slowest-budgeted module the fix moves, and a fix that moves no module has no fix budget. The plan says core, // leaf or none, so mesh-delivery can pass it on with the fix's delivery. func TestAChangePlanSaysTheClassOfWhatItMoves(t *testing.T) { const repo = "http://forge.internal:20000/novox/mesh-catalog.git" entry := func(name, path string) inventory.Entry { e := fromRepo(name, repo, path) e.Source.BuiltFrom = "old" e.On = []string{"anchor"} return e } gitea := entry("gitea", "modules/gitea") resolver := entry("dnsmasq", "modules/dnsmasq") resolver.Manifest.Claims = []catalogue.Claim{{Name: resolverSeat}} delivery := entry(catalogue.DeliverySeat, "modules/mesh-delivery") webApp := entry("photos", "modules/photos") entries := []inventory.Entry{gitea, resolver, delivery, webApp} // photos stands on gitea: a change to gitea moves photos as its dependent. edges := []inventory.Edge{{From: "photos", To: "gitea", Kind: inventory.EdgeStandsOn}} policy := func(string) (inventory.Upgrade, bool) { return inventory.Upgrade{RollOut: true}, true } plan := func(paths ...string) link.ChangePlan { m := link.SourceMoved{Owner: "novox", Repo: "mesh-catalog", Base: "main", Commit: "head", Paths: paths} return changePlanOf("novox/mesh-catalog", "main", "head", reachOfMerge(m, entries, nil, edges), entries, policy) } for _, c := range []struct { why string paths []string want string }{ {"a leaf module and its dependent", []string{"modules/gitea/index.ts"}, inventory.ClassLeaf}, {"the delivery's owner, on the controller's own path", []string{"modules/mesh-delivery/cmd/x.go"}, inventory.ClassCore}, {"the mesh's resolver", []string{"modules/dnsmasq/module.json"}, inventory.ClassCore}, {"a leaf and a core module together: the slowest-budgeted", []string{"modules/gitea/index.ts", "modules/dnsmasq/module.json"}, inventory.ClassCore}, {"nothing any module's build reads", []string{"README.md"}, "none"}, {"a new leaf module alone", []string{"modules/weather/module.json"}, inventory.ClassLeaf}, {"a new module on the controller's own path, by its own class", []string{"next/mesh-delivery/module.json"}, inventory.ClassCore}, {"a new leaf module beside a core one moved", []string{"modules/weather/module.json", "modules/dnsmasq/module.json"}, inventory.ClassCore}, } { if got := plan(c.paths...).Class; got != c.want { t.Errorf("%s: class %q, want %q", c.why, got, c.want) } } }