package contracts_test import ( "encoding/json" "os" "strings" "testing" ) func TestCurrentContractTopology(t *testing.T) { type route struct { RoutingKey string `json:"routing_key"` BindingKey string `json:"binding_key"` Queue string `json:"queue"` } var topology struct { Ownership string `json:"ownership"` Dispatcher struct { Exchange string `json:"exchange"` Control route `json:"control"` Task route `json:"task"` } `json:"dispatcher"` SaaS struct { Exchange string `json:"exchange"` Result route `json:"result"` } `json:"saas"` } data, err := os.ReadFile("local/mq-topology.json") if err != nil { t.Fatal(err) } if err := json.Unmarshal(data, &topology); err != nil { t.Fatal(err) } if topology.Ownership != "saas" || topology.Dispatcher.Exchange != "agent-call.dispatchers.v1" || topology.SaaS.Exchange != "agent-call.saas.v1" { t.Fatalf("unapproved owner/exchanges: %+v", topology) } if topology.Dispatcher.Control.Queue != "agent-call.d..control.v1" || topology.Dispatcher.Control.BindingKey != "d..control.in" { t.Fatalf("wrong control queue or exact binding: %+v", topology.Dispatcher.Control) } if topology.Dispatcher.Task.Queue != "agent-call.d..task..v1" || topology.Dispatcher.Task.BindingKey != "d..task..in" { t.Fatalf("wrong per-task queue or binding: %+v", topology.Dispatcher.Task) } result := topology.SaaS.Result if result.Queue != "agent-call.saas.events.v1" || result.RoutingKey != "d..out" || result.BindingKey != result.RoutingKey { t.Fatalf("SaaS must consume a shared queue bound exactly to each D: %+v", result) } for _, r := range []route{topology.Dispatcher.Control, topology.Dispatcher.Task, result} { if r.RoutingKey != r.BindingKey || strings.ContainsAny(r.BindingKey, "*#") { t.Fatalf("route must have exact binding: %+v", r) } } for _, id := range []string{"d-1", "d-2"} { key := strings.ReplaceAll(result.RoutingKey, "", id) if len(key) > 255 || key == result.BindingKey { t.Fatalf("invalid dispatcher-specific binding: %q", key) } } }