A module's dependencies are one relation in the catalogue — stands-on, packages, built-by, declared — answered by one call. A merge takes what moved and everything reachable from it, sorts the set into tiers (a code dependency in the same tier, a build dependency after its base is built, a runtime dependency after the build machine is built and running; the build machine's own base comes first, built by the one that runs), writes the plan to the store, asks the first tier and returns. Every outcome advances the plan; a ticker advances what outcomes cannot; a controller replaced mid-plan resumes it. status lists open plans and names one that has waited too long.
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package inventory
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/catalogue"
|
|
)
|
|
|
|
// The catalogue's one dependency relation (novox/hq ADR 0162): four kinds of edge from one call.
|
|
func TestDependenciesAreOneRelationWithTheirKinds(t *testing.T) {
|
|
entry := func(name, repository string) Entry {
|
|
return Entry{Manifest: catalogue.Manifest{Module: name}, Source: Source{Repository: repository}}
|
|
}
|
|
builder := entry("builder", "http://forge/novox/mesh-catalog.git")
|
|
builder.Manifest.Claims = []catalogue.Claim{{Name: "mesh-build-machine", Scope: catalogue.ScopeMesh}}
|
|
plugin := entry("shop-plugin", "http://forge/novox/mesh-catalog.git")
|
|
plugin.Manifest.Build = &catalogue.Build{On: []catalogue.BuildsOn{{Arg: "BASE", Module: "shop"}}}
|
|
entries := []Entry{
|
|
entry("mesh-tools", "http://forge/novox/mesh-tools.git"),
|
|
entry("shop", "http://forge/novox/mesh-catalog.git"),
|
|
plugin,
|
|
builder,
|
|
entry("mesh-controller", "http://forge/novox/mesh-controller.git"),
|
|
entry("route-proxy", "http://forge/novox/mesh-catalog.git"),
|
|
{Manifest: catalogue.Manifest{Module: "hand-made"}},
|
|
}
|
|
against := map[string][]string{
|
|
"shop": {catalogue.ArtifactStoreScheme + "mesh-tools/runtime@sha256:a"},
|
|
"builder": {catalogue.ArtifactStoreScheme + "mesh-tools/runtime@sha256:a"},
|
|
}
|
|
read := map[string][]ReadRepository{
|
|
"route-proxy": {{Repository: "http://forge/novox/mesh-controller.git", Ref: "main"}},
|
|
}
|
|
got := dependenciesOf(entries, against, read)
|
|
has := func(from, to, kind string) bool {
|
|
for _, e := range got {
|
|
if e == (Edge{From: from, To: to, Kind: kind}) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
for _, want := range []Edge{
|
|
{"shop", "mesh-tools", EdgeStandsOn},
|
|
{"builder", "mesh-tools", EdgeStandsOn},
|
|
{"shop-plugin", "shop", EdgeDeclared},
|
|
{"route-proxy", "mesh-controller", EdgePackages},
|
|
{"shop", "builder", EdgeBuiltBy},
|
|
{"mesh-controller", "builder", EdgeBuiltBy},
|
|
{"mesh-tools", "builder", EdgeBuiltBy},
|
|
} {
|
|
if !has(want.From, want.To, want.Kind) {
|
|
t.Errorf("missing %+v in %+v", want, got)
|
|
}
|
|
}
|
|
if has("builder", "builder", EdgeBuiltBy) {
|
|
t.Error("the builder is not built by itself")
|
|
}
|
|
for _, e := range got {
|
|
if e.From == "hand-made" {
|
|
t.Errorf("a module with no source depends on nothing: %+v", e)
|
|
}
|
|
}
|
|
}
|