The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
42 lines
1.7 KiB
Go
42 lines
1.7 KiB
Go
package judge
|
|
|
|
import (
|
|
"maps"
|
|
"reflect"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// Design 47 G §491: two modules whose entries carry one Go module path are both refused, naming both; one name in two
|
|
// ecosystems, or one module's two artifacts of one name, is no problem.
|
|
func TestPackageNameProblems(t *testing.T) {
|
|
pkg := func(module, ecosystem, name string) meshcatalog.CatalogEntry {
|
|
return meshcatalog.CatalogEntry{Module: module, Artifacts: []meshcatalog.Artifact{{Ref: module + ":p", Package: &meshcatalog.ArtifactPackage{Ecosystem: ecosystem, Name: name}}}}
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
entries []meshcatalog.CatalogEntry
|
|
want []string
|
|
}{
|
|
{"two modules, one Go name", []meshcatalog.CatalogEntry{pkg("a", "go", "x/y"), pkg("b", "go", "x/y"), pkg("c", "go", "x/z")}, []string{"a", "b"}},
|
|
{"one name, two ecosystems", []meshcatalog.CatalogEntry{pkg("a", "go", "x"), pkg("b", "npm", "x")}, nil},
|
|
{"one module twice", []meshcatalog.CatalogEntry{{Module: "a", Artifacts: []meshcatalog.Artifact{
|
|
{Ref: "a:p", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "x"}}, {Ref: "a:q", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "x"}}}}}, nil},
|
|
}
|
|
for _, c := range cases {
|
|
got := PackageNameProblems(c.entries)
|
|
modules := slices.Sorted(maps.Keys(got))
|
|
if !reflect.DeepEqual(modules, c.want) && (len(modules) > 0 || len(c.want) > 0) {
|
|
t.Errorf("%s: refused %v, want %v", c.name, modules, c.want)
|
|
}
|
|
for m, problems := range got {
|
|
if len(problems) != 1 || !strings.Contains(problems[0], strings.Join(c.want, " and ")) {
|
|
t.Errorf("%s: %s's problems %q do not name %v", c.name, m, problems, c.want)
|
|
}
|
|
}
|
|
}
|
|
}
|