issue 1840/S3: look the declared packages up by name in the mirror's integration test, since every node also runs the mesh's own modules and their packages
This commit is contained in:
@@ -35,19 +35,47 @@ func TestTheDeclaredPackagesMirrorNamesWhatEachNodesModulesDeclare(t *testing.T)
|
|||||||
if err := json.Unmarshal(first["anchor"], &got); err != nil {
|
if err := json.Unmarshal(first["anchor"], &got); err != nil {
|
||||||
t.Fatalf("anchor has no value: %v", err)
|
t.Fatalf("anchor has no value: %v", err)
|
||||||
}
|
}
|
||||||
want := []inventory.PackageDeclared{{Package: "curl", Modules: []string{"fetcher", "viewer"}},
|
// Every node also runs the mesh's own modules, which declare packages of their own: curl and nano are looked
|
||||||
{Package: "nano", Modules: []string{"viewer"}, Absent: true}}
|
// up by name, and no package names viewer or fetcher but those they declare.
|
||||||
if len(got.Packages) != len(want) {
|
byName := map[string]inventory.PackageDeclared{}
|
||||||
t.Fatalf("anchor declares %+v, want %+v", got.Packages, want)
|
for _, p := range got.Packages {
|
||||||
|
byName[p.Package] = p
|
||||||
}
|
}
|
||||||
for i, p := range want {
|
same := func(a, b []string) bool {
|
||||||
if g := got.Packages[i]; g.Package != p.Package || g.Absent != p.Absent || len(g.Modules) != len(p.Modules) ||
|
if len(a) != len(b) {
|
||||||
(len(p.Modules) > 0 && g.Modules[0] != p.Modules[0]) {
|
return false
|
||||||
t.Errorf("package %d is %+v, want %+v", i, g, p)
|
}
|
||||||
|
for i := range a {
|
||||||
|
if a[i] != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, p := range []inventory.PackageDeclared{{Package: "curl", Modules: []string{"fetcher", "viewer"}},
|
||||||
|
{Package: "nano", Modules: []string{"viewer"}, Absent: true}} {
|
||||||
|
if g, ok := byName[p.Package]; !ok || g.Absent != p.Absent || !same(g.Modules, p.Modules) {
|
||||||
|
t.Errorf("anchor declares %s as %+v, want %+v (all: %+v)", p.Package, g, p, got.Packages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if string(first["laptop"]) != `{"node":"laptop","packages":[]}` {
|
for _, p := range got.Packages {
|
||||||
t.Errorf("a node declaring none is %s", first["laptop"])
|
if p.Package == "curl" || p.Package == "nano" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, m := range p.Modules {
|
||||||
|
if m == "viewer" || m == "fetcher" {
|
||||||
|
t.Errorf("%s is said to be declared by %s, which does not declare it", p.Package, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var laptop inventory.DeclaredPackagesMirrored
|
||||||
|
if err := json.Unmarshal(first["laptop"], &laptop); err != nil || laptop.Node != "laptop" || laptop.Packages == nil {
|
||||||
|
t.Errorf("a node assigned neither module has no value of its own: %s (%v)", first["laptop"], err)
|
||||||
|
}
|
||||||
|
for _, p := range laptop.Packages {
|
||||||
|
if p.Package == "curl" || p.Package == "nano" {
|
||||||
|
t.Errorf("laptop is assigned neither module and declares %+v", p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
second, err := source(ctx)
|
second, err := source(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user