package resolution import ( "strings" "testing" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // The zone is the operator's (a setting) and the port is where this machine publishes the listen — // neither is the definition's to state. func TestAZoneIsPlacedFromTheNodesSettingAndPublishedPort(t *testing.T) { m := mcat.Manifest{Module: "lab", Zone: &mcat.Zone{Name: "${setting:zone}", Listen: "dns"}, Listens: []mcat.Listening{{Name: "dns", Port: 5353, From: mcat.FromMesh}}} z, err := ZoneOn(m, []mcat.Layer{{From: "node", Values: map[string]any{"zone": "Incus."}}}, map[int]int{5353: 15353}, "workstation", "10.77.0.3") if err != nil { t.Fatal(err) } if z.Zone != "incus" || z.Address != "10.77.0.3" || z.Port != 15353 || z.Node != "workstation" { t.Fatalf("the zone was placed as %+v", *z) } if _, err := ZoneOn(m, nil, nil, "workstation", "10.77.0.3"); err == nil { t.Fatal("a zone nobody named was placed") } } // One module answers a zone, and none may shadow the mesh's names or a public domain. func TestTheMeshRefusesAZoneTwiceOrOneThatShadows(t *testing.T) { one := mcat.ZoneAt{Zone: "incus", Node: "workstation", Module: "lab", Address: "10.77.0.3", Port: 53} if p := ZonesProblems([]mcat.ZoneAt{one}, "internal", []string{"example.tld"}); len(p) != 0 { t.Fatalf("one ordinary zone was refused: %v", p) } twice := one twice.Node, twice.Module = "laptop", "other" cases := map[string][]mcat.ZoneAt{ "declared by": {one, twice}, "mesh's own suffix": {{Zone: "lab.internal", Node: "a", Module: "m"}}, "public domain": {{Zone: "dev.example.tld", Node: "a", Module: "m"}}, } for want, zones := range cases { p := strings.Join(ZonesProblems(zones, "internal", []string{"example.tld"}), "\n") if !strings.Contains(p, want) { t.Errorf("not refused for %q: %q", want, p) } } }