62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// 1840/AC5 (ADR 0507 §5): the source of the declared-packages mirror composes each node and names, for a package two modules
|
|
// declare and one declared absent, the modules that declare it; the same records give the same bytes on a second pass, so
|
|
// the mirror writes nothing; a node with no package has a key that says so.
|
|
func TestTheDeclaredPackagesMirrorNamesWhatEachNodesModulesDeclare(t *testing.T) {
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
register(t, open, catalogue.Manifest{Module: "viewer", Version: "1", Resources: []map[string]any{
|
|
{"id": "pkg-curl", "type": "package", "package": "curl"},
|
|
{"id": "pkg-nano", "type": "package", "package": "nano", "absent": true}}})
|
|
register(t, open, catalogue.Manifest{Module: "fetcher", Version: "1", Resources: []map[string]any{
|
|
{"id": "pkg-curl", "type": "package", "package": "curl"}}})
|
|
for _, module := range []string{"viewer", "fetcher"} {
|
|
if _, err := assign(ctx, open, "anchor", module); err != nil {
|
|
t.Fatalf("assign anchor %s: %v", module, err)
|
|
}
|
|
}
|
|
source := declaredPackagesMirror(open)
|
|
first, err := source(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var got inventory.DeclaredPackagesMirrored
|
|
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)
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
if string(first["laptop"]) != `{"node":"laptop","packages":[]}` {
|
|
t.Errorf("a node declaring none is %s", first["laptop"])
|
|
}
|
|
second, err := source(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for node, value := range first {
|
|
if string(second[node]) != string(value) {
|
|
t.Errorf("the value of %s changed between two passes over the same records:\n%s\n%s", node, value, second[node])
|
|
}
|
|
}
|
|
}
|