Swaps three import paths for mesh-sdk's go/catalogue, go/overlay and go/validate (the same packages, copied from this repository at 6c2a8d62) and lets gofmt order the groups. The six swap commits compile together once the pin commit (go.mod, modules.txt) is on the branch; each alone does not, because a file on the SDK's types cannot call one still on the old package.
56 lines
2.8 KiB
Go
56 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/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")
|
|
delivery.Manifest.Claims = []catalogue.Claim{{Name: catalogue.DeliverySeat}}
|
|
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-host/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)
|
|
}
|
|
}
|
|
}
|