A take-in's movers are the modules registered for a repository the source revision moved whose fingerprint differs from their entry in the branch's newest catalog revision, and every module, in any repository, importing a package one of them publishes. A module of another repository is no mover by its fingerprint alone; one with no build is none. Builds: design 47 H §743 (movers); A-476a Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
61 lines
2.7 KiB
Go
61 lines
2.7 KiB
Go
package index
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
)
|
|
|
|
// A take-in's movers (design 47 H §743, A-476a): the moved repository's modules whose fingerprint moved, and every module that
|
|
// imports a package of one of them; a module of another repository is no mover by its fingerprint alone.
|
|
func TestMoversOf(t *testing.T) {
|
|
sdk := func(fp string) meshcatalog.CatalogEntry {
|
|
return meshcatalog.CatalogEntry{Module: "mesh-sdk", Repository: "novox/mesh-sdk", Commit: "s" + fp, Fp: fp,
|
|
Artifacts: []meshcatalog.Artifact{{Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}
|
|
}
|
|
importer := meshcatalog.CatalogEntry{Module: "gate", Repository: "novox/mesh-catalog", Commit: "g1", Fp: "g",
|
|
Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.20"}}
|
|
other := func(fp string) meshcatalog.CatalogEntry {
|
|
return meshcatalog.CatalogEntry{Module: "feh", Repository: "novox/mesh-catalog", Commit: "f1", Fp: fp}
|
|
}
|
|
entries := func(es ...meshcatalog.CatalogEntry) map[string]meshcatalog.CatalogEntry {
|
|
m := map[string]meshcatalog.CatalogEntry{}
|
|
for _, e := range es {
|
|
m[e.Module] = e
|
|
}
|
|
return m
|
|
}
|
|
for _, c := range []struct {
|
|
name string
|
|
before []meshcatalog.CatalogEntry
|
|
after map[string]meshcatalog.CatalogEntry
|
|
moved []string
|
|
want []string
|
|
}{
|
|
{"a mesh-sdk commit moves mesh-sdk and its importers", []meshcatalog.CatalogEntry{sdk("1"), importer, other("f")},
|
|
entries(sdk("2"), importer, other("f")), []string{"novox/mesh-sdk"}, []string{"gate", "mesh-sdk"}},
|
|
{"a commit changing only a document names no mover", []meshcatalog.CatalogEntry{sdk("1"), importer},
|
|
entries(sdk("1"), importer), []string{"novox/mesh-sdk"}, nil},
|
|
{"a module not registered for the moved repository is no mover", []meshcatalog.CatalogEntry{sdk("1"), other("f")},
|
|
entries(sdk("1"), other("f2")), []string{"novox/mesh-sdk"}, nil},
|
|
{"a module the newest revision does not hold moves", nil,
|
|
entries(other("f")), []string{"novox/mesh-catalog"}, []string{"feh"}},
|
|
{"a module with no fingerprint is no mover", nil,
|
|
entries(other("")), []string{"novox/mesh-catalog"}, nil},
|
|
} {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
var got []string
|
|
for _, m := range moversOf(c.before, c.after, c.moved) {
|
|
if e := c.after[m.Module]; m.Commit != e.Commit || m.Fingerprint != e.Fp || m.Repository != e.Repository {
|
|
t.Errorf("mover %s = %+v, not its entry's commit, fingerprint and repository", m.Module, m)
|
|
}
|
|
got = append(got, m.Module)
|
|
}
|
|
if !reflect.DeepEqual(got, c.want) {
|
|
t.Errorf("movers = %v, want %v", got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|