Files
mesh-delivery/modules/mesh-delivery-builder/internal/versions/entrynames_test.go
T
jschoubben e84e2adff0 builder: answer reserved for a bundle's or an archive's name, and log a name no entry carries
distribution's tag of mesh-delivery-pipeline 0.1.6 was refused: reserved answered 'no entry carries the name
mesh-delivery-pipeline/program', since the lookup matched only an artifact's package name and a bundle's entry
names none. A bundle's or an archive's name is <module>/<artifact>, read from its reference through NameOf; a
name no entry carries is said in the builder's log with the entries looked at.

Builds: design 47 G A-418, §478, §572
2026-11-15 03:00:14 +01:00

88 lines
4.2 KiB
Go

package versions
import (
"context"
"reflect"
"strings"
"testing"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
)
func named(module, artifact, name string) meshcatalog.CatalogEntry {
return meshcatalog.CatalogEntry{Module: module, Artifacts: []meshcatalog.Artifact{
{Ref: module + ":" + artifact, Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: name}}}}
}
// TestPackageNamesAreReadFromTheCatalogHalfsEntries: a package's name in its ecosystem is the name the entry of its module gives the
// artifact (design 47 G §348, §676), the module and artifact a name is built from are the entries carrying it, and a name two
// entries carry is an error naming both (§491); no state of the indexer is read.
func TestPackageNamesAreReadFromTheCatalogHalfsEntries(t *testing.T) {
entries := func() []meshcatalog.CatalogEntry {
return []meshcatalog.CatalogEntry{named("mesh-sdk", "go", "git.novox.be/novox/mesh-sdk/go"), named("netcheck", "lib", "netcheck"),
named("twin-a", "lib", "twin"), named("twin-b", "lib", "twin"), {Module: "bare"},
{Module: "pipe", Artifacts: []meshcatalog.Artifact{{Ref: "pipe:program", Kind: KindBundle}, {Ref: "pipe:img", Kind: KindImage}}}}
}
ctx := context.Background()
for _, c := range []struct {
module, artifact string
name string
known bool
}{
{"mesh-sdk", "go", "git.novox.be/novox/mesh-sdk/go", true},
{"netcheck", "lib", "netcheck", true},
{"netcheck", "other", "", false},
{"bare", "lib", "", false},
{"unknown", "lib", "", false},
} {
got, known, err := NamesFrom(entries)(ctx, c.module, c.artifact)
if err != nil || got != c.name || known != c.known {
t.Errorf("NamesFrom(%s/%s) = %q, %v, %v; want %q, %v", c.module, c.artifact, got, known, err, c.name, c.known)
}
}
module, artifact, found, err := ModuleFrom(entries)(ctx, "netcheck")
if module != "netcheck" || artifact != "lib" || !found || err != nil {
t.Errorf("ModuleFrom(netcheck) = %q, %q, %v, %v", module, artifact, found, err)
}
if _, _, found, err := ModuleFrom(entries)(ctx, "nobody"); found || err != nil {
t.Errorf("ModuleFrom(nobody) = %v, %v; want none", found, err)
}
if _, _, _, err := ModuleFrom(entries)(ctx, "twin"); err == nil {
t.Error("ModuleFrom(twin): two entries carry it, want an error")
}
// Design 47 G A-418: a bundle is carried as <module>/<artifact>, from its reference, with no package in its entry; a kind
// that is neither a bundle nor an archive is not named so.
if got, _ := CarriersFrom(entries)(ctx, "pipe/program"); !reflect.DeepEqual(got, []Built{{"pipe", "program"}}) {
t.Errorf("CarriersFrom(pipe/program) = %v, want the bundle pipe:program", got)
}
if got, _ := CarriersFrom(entries)(ctx, "pipe/img"); len(got) != 0 {
t.Errorf("CarriersFrom(pipe/img) = %v, want none: an image with no package is named nothing", got)
}
if looked := LookedAt(entries); !strings.Contains(looked, "6 entries") || !strings.Contains(looked, "pipe:program as pipe/program") {
t.Errorf("LookedAt = %q, want the six entries and the bundle's name", looked)
}
got, _ := CarriersFrom(entries)(ctx, "twin")
if want := []Built{{"twin-a", "lib"}, {"twin-b", "lib"}}; !reflect.DeepEqual(got, want) {
t.Errorf("CarriersFrom(twin) = %v, want %v", got, want)
}
}
// Design 47 G A-119: the floor's requirements are what the catalog half's entries name for the package, each version once.
func TestRequirementsFromAreTheVersionsEntriesNameForAPackage(t *testing.T) {
entries := func() []meshcatalog.CatalogEntry {
return []meshcatalog.CatalogEntry{
{Module: "a", Packages: map[string]string{"x/sdk": "v0.0.0-2026-aaa", "y": "v1.0.0"}},
{Module: "b", Packages: map[string]string{"x/sdk": "v0.0.0-2026-bbb"}},
{Module: "c", Packages: map[string]string{"x/sdk": "v0.0.0-2026-aaa"}},
{Module: "d"},
}
}
got, err := RequirementsFrom(entries)(context.Background(), "x/sdk")
if err != nil || !reflect.DeepEqual(got, []string{"v0.0.0-2026-aaa", "v0.0.0-2026-bbb"}) {
t.Errorf("requirements = %v, %v", got, err)
}
if got, _ := RequirementsFrom(entries)(context.Background(), "none"); len(got) != 0 {
t.Errorf("a package no entry names has requirements %v", got)
}
}