package resolution import ( "strings" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) func containersOf(t *testing.T, r mcat.Resolution, with mcat.Rendering) []map[string]any { t.Helper() out, err := Declaration(r, with) if err != nil { t.Fatal(err) } var found []map[string]any for _, res := range out { if res["type"] == "container" { found = append(found, res) } } return found } func namesOf(r map[string]any) []string { var out []string if given, ok := r["hosts"].([]any); ok { for _, h := range given { out = append(out, h.(string)) } } return out } // No resource is given a `hosts` key it did not declare. A file or a service carrying one is a // declaration the host refuses outright — it takes no unknown field — so an invented key breaks // the whole machine rather than one resource. func TestNothingIsGivenNamesItDidNotDeclare(t *testing.T) { out, err := Declaration(mcat.Resolution{Node: "laptop", Modules: []mcat.Manifest{{ Module: "app", Resources: []map[string]any{ {"id": "conf", "type": "file", "path": "/etc/app.conf", "content": "x", "mode": "0644"}, {"id": "run", "type": "service", "unit": "app.service", "state": "running"}, {"id": "web", "type": "container", "name": "web", "image": "registry.example/web@sha256:" + strings.Repeat("a", 64)}, }, }}}, mcat.Rendering{Names: map[string]string{"anchor.internal": "10.42.0.1"}}) if err != nil { t.Fatal(err) } for _, r := range out { if _, given := r["hosts"]; given { t.Fatalf("a %v was given names it never declared: %v", r["type"], r) } } }