From e022a3fd6ff43a47f5b1ef7b8e709e389f45e328 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 22 Oct 2026 17:52:40 +0200 Subject: [PATCH] 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 --- .../declared_packages_integration_test.go | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/cmd/mesh-controller/declared_packages_integration_test.go b/cmd/mesh-controller/declared_packages_integration_test.go index 4a74e243..c99ca3da 100644 --- a/cmd/mesh-controller/declared_packages_integration_test.go +++ b/cmd/mesh-controller/declared_packages_integration_test.go @@ -35,19 +35,47 @@ func TestTheDeclaredPackagesMirrorNamesWhatEachNodesModulesDeclare(t *testing.T) if err := json.Unmarshal(first["anchor"], &got); err != nil { t.Fatalf("anchor has no value: %v", err) } - want := []inventory.PackageDeclared{{Package: "curl", Modules: []string{"fetcher", "viewer"}}, - {Package: "nano", Modules: []string{"viewer"}, Absent: true}} - if len(got.Packages) != len(want) { - t.Fatalf("anchor declares %+v, want %+v", got.Packages, want) + // Every node also runs the mesh's own modules, which declare packages of their own: curl and nano are looked + // up by name, and no package names viewer or fetcher but those they declare. + byName := map[string]inventory.PackageDeclared{} + for _, p := range got.Packages { + byName[p.Package] = p } - for i, p := range want { - if g := got.Packages[i]; g.Package != p.Package || g.Absent != p.Absent || len(g.Modules) != len(p.Modules) || - (len(p.Modules) > 0 && g.Modules[0] != p.Modules[0]) { - t.Errorf("package %d is %+v, want %+v", i, g, p) + same := func(a, b []string) bool { + if len(a) != len(b) { + return false + } + 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":[]}` { - t.Errorf("a node declaring none is %s", first["laptop"]) + for _, p := range got.Packages { + 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) if err != nil {