Files
mesh-delivery/modules/mesh-delivery-builder/internal/versions/entrynames_test.go
T
jschoubben 481d1f255b B1a: the builder's version floor and its wait go
The numbering from before G goes with its floor wait (design 47 H §756): the
builder asks no floor (seat git.tags, the registry seats' versions, the
entries' requirements), keeps no state floor-waits, serves neither
builder_floor_again nor builder_floor_waits, raises no floor-silent finding
and hears no take-in.taken or condition-cleared to wake one. The claim
numbering that asked the floor (Numberer.Number, build.Numbers) goes with it;
the reservation is the one place a version is numbered.

Builds: design 47 H §756, G §372, spec 29, 41, 47, 48
2026-11-23 11:48:06 +01:00

69 lines
3.3 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)
}
}