package catalogue import ( "strings" "testing" ) func configured(block map[string]any) SettingsBy { return SettingsBy{"media": {{From: "node anchor", Placement: map[string]any{EndpointsSetting: block}}}} } // An endpoint the module does not declare reaches nothing, and the refusal says what it does declare. func TestConfiguringAnEndpointTheModuleLacksIsRefused(t *testing.T) { _, err := Endpoints(aMediaServer(), configured(map[string]any{ "admin": map[string]any{"reach": ReachInternal}})["media"]) if err == nil || !strings.Contains(err.Error(), "does not declare") { t.Fatalf("configuring an absent endpoint was accepted: %v", err) } if err != nil && !strings.Contains(err.Error(), "stream") { t.Fatalf("the refusal does not name what the module declares: %v", err) } } func TestAReachInABlockIsHeldToTheFourValues(t *testing.T) { _, err := Endpoints(aMediaServer(), configured(map[string]any{ "web": map[string]any{"reach": "mesh"}})["media"]) if err == nil || !strings.Contains(err.Error(), "a reach is") { t.Fatalf("a filter word was accepted as a reach: %v", err) } } // And the same for its reach, said once here and once through the older key. func TestAnEndpointWhoseReachIsAlsoExposedIsRefused(t *testing.T) { _, err := Endpoints(aMediaServer(), []Layer{{From: "node anchor", Placement: map[string]any{ EndpointsSetting: map[string]any{"web": map[string]any{"reach": ReachInternal}}, ExposeSetting: map[string]any{"80": FromEverywhere}, }}}) if err == nil || !strings.Contains(err.Error(), "same thing in different words") { t.Fatalf("a reach said two ways was accepted: %v", err) } } // A module whose endpoints are unnamed cannot be configured this way, and is told so rather than // having a block silently reach nothing — which is every module in the catalogue today. func TestAModuleWithNoNamedEndpointsIsToldSo(t *testing.T) { m := Manifest{Module: "media", Listens: []Listening{{Port: 80, From: FromMesh}}} _, err := Endpoints(m, configured(map[string]any{"web": map[string]any{"reach": ReachBoth}})["media"]) if err == nil || !strings.Contains(err.Error(), "no endpoints by name") { t.Fatalf("a module with no named endpoints accepted a block: %v", err) } }