package catalogue import ( "testing" ) // aMediaServer is the shape one port number per key cannot express: two endpoints of different kinds. // A web surface a proxy serves under a subdomain, and a protocol port clients dial directly because // the client expects that number. func aMediaServer() Manifest { return Manifest{ Module: "media", Listens: []Listening{ {Name: "web", Port: 80, From: FromMesh, Why: "the app, behind the proxy"}, {Name: "stream", Port: 32400, From: FromEverywhere, Fixed: true, Why: "the client dials this number; the protocol chose it"}, }, Contributes: map[string]map[string]any{ "route": {"label": "media", RouteEndpoint: "web"}, }, // Both endpoints are published by its container, which is what lets a machine port be given // for either: the mesh moves a port the module publishes, never one it merely listens on. Resources: []map[string]any{ {"id": "server", "type": "container", "name": "media", "ports": []any{"80", "32400"}}, }, } } // **A route names the endpoint it serves.** A route and a listen both carried a port and nothing said // they were the same thing; now one of them says so. func TestARouteNamesTheEndpointItServes(t *testing.T) { m := aMediaServer() if port, ok := EndpointPort(m, "web"); !ok || port != 80 { t.Fatalf("the web endpoint resolves to %d (%v), want 80", port, ok) } if port, ok := EndpointPort(m, "stream"); !ok || port != 32400 { t.Fatalf("the stream endpoint resolves to %d (%v), want 32400", port, ok) } if _, ok := EndpointPort(m, "absent"); ok { t.Fatal("an endpoint the module does not declare resolved to a port") } }