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) } } }