59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package mq
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.ipao.vip/rogee/go-sip/internal/tenant"
|
|
)
|
|
|
|
func TestCurrentBrokerInboundRequiresExactQueueRouteOwnerAndSchema(t *testing.T) {
|
|
control, err := tenant.CurrentControlRoute(currentTestDispatcherID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
task, err := tenant.CurrentTaskRoute(currentTestDispatcherID, "task-asr")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
broker := &CurrentBroker{dispatcherID: currentTestDispatcherID, controlQueue: control.Queue}
|
|
for _, tc := range []struct {
|
|
name, queue, route, fixture string
|
|
wantError bool
|
|
}{
|
|
{"control", control.Queue, control.BindingKey, "mq-control", false},
|
|
{"sip change", control.Queue, control.BindingKey, "mq-sip-change", false},
|
|
{"execute", task.Queue, task.BindingKey, "mq-execute", false},
|
|
{"wrong queue", "agent-call.d.c046b893-8628-4589-ae50-619d049248a7.task.task-asr.v1", task.BindingKey, "mq-execute", true},
|
|
{"wrong route", task.Queue, control.BindingKey, "mq-execute", true},
|
|
{"execute on control", control.Queue, control.BindingKey, "mq-execute", true},
|
|
{"control on task", task.Queue, task.BindingKey, "mq-control", true},
|
|
{"old schema", task.Queue, task.BindingKey, "invalid/mq-legacy-schema-version", true},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := broker.validateInbound(tc.queue, tc.route, currentMessage(t, tc.fixture))
|
|
if (err != nil) != tc.wantError {
|
|
t.Fatalf("wanted error=%v, got %v", tc.wantError, err)
|
|
}
|
|
})
|
|
}
|
|
foreign := []byte(strings.Replace(string(currentMessage(t, "mq-execute")), currentTestDispatcherID, "c046b893-8628-4589-ae50-619d049248a7", 1))
|
|
if err := broker.validateInbound(task.Queue, task.BindingKey, foreign); err == nil {
|
|
t.Fatal("accepted wrong Dispatcher owner")
|
|
}
|
|
}
|
|
|
|
func TestCurrentBrokerRejectsControlQueueFromSilentTaskDrain(t *testing.T) {
|
|
control, err := tenant.CurrentControlRoute(currentTestDispatcherID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
broker := &CurrentBroker{dispatcherID: currentTestDispatcherID, controlQueue: control.Queue}
|
|
if err := broker.validateQueue(control.Queue, false); err == nil {
|
|
t.Fatal("allowed task-drain to silently ACK controls")
|
|
}
|
|
if err := broker.validateQueue(control.Queue, true); err != nil {
|
|
t.Fatalf("control consumer cannot read own queue: %v", err)
|
|
}
|
|
}
|