Files
go-sip/internal/tenant/current_test.go
T

59 lines
2.2 KiB
Go

package tenant
import (
"strings"
"testing"
)
func TestCurrentTaskAndControlRoutesAreExactAndPartitioned(t *testing.T) {
d1 := "c046b893-8628-4589-ae50-619d049248a6"
d2 := "c046b893-8628-4589-ae50-619d049248a7"
control, err := CurrentControlRoute(d1)
if err != nil {
t.Fatal(err)
}
if control.Exchange != "agent-call.dispatchers.v1" || control.BindingKey != "d."+d1+".control.in" || control.Queue != "agent-call.d."+d1+".control.v1" {
t.Fatalf("unapproved control route: %+v", control)
}
task, err := CurrentTaskRoute(d1, "task-1")
if err != nil {
t.Fatal(err)
}
if task.Exchange != control.Exchange || task.BindingKey != "d."+d1+".task.task-1.in" || task.Queue != "agent-call.d."+d1+".task.task-1.v1" {
t.Fatalf("unapproved task route: %+v", task)
}
other, err := CurrentTaskRoute(d2, "task-1")
if err != nil || task.Queue == other.Queue || task.BindingKey == other.BindingKey {
t.Fatalf("Dispatcher queue collision: %+v, %+v, %v", task, other, err)
}
shared1, err := CurrentResultRoute(d1)
if err != nil {
t.Fatal(err)
}
shared2, err := CurrentResultRoute(d2)
if err != nil {
t.Fatal(err)
}
if shared1.Exchange != "agent-call.saas.v1" || shared1.Queue != "agent-call.saas.events.v1" || shared1.Queue != shared2.Queue || shared1.BindingKey != "d."+d1+".out" || shared2.BindingKey != "d."+d2+".out" {
t.Fatalf("SaaS result queue must be shared with exact D-specific bindings: %+v, %+v", shared1, shared2)
}
}
func TestCurrentTaskRoutingRejectsWildcardAndOverflow(t *testing.T) {
d := "c046b893-8628-4589-ae50-619d049248a6"
for _, taskID := range []string{"", "task.*", "task.#", "task.with.dot", "task/with/slash", strings.Repeat("a", 129)} {
if _, err := CurrentTaskRoute(d, taskID); err == nil {
t.Fatalf("accepted unsafe task identifier %q", taskID)
}
}
for _, dID := range []string{"not-a-uuid", "C046B893-8628-4589-AE50-619D049248A6", ""} {
if _, err := CurrentControlRoute(dID); err == nil {
t.Fatalf("accepted unsafe D identity %q", dID)
}
}
long, err := CurrentTaskRoute(d, strings.Repeat("a", 128))
if err != nil || len(long.BindingKey) > 255 || len(long.Queue) > 255 {
t.Fatalf("valid task exceeded AMQP route limits: %+v %v", long, err)
}
}