Files
mesh-sdk/go/process/event_hub_test.go
T
jschoubben 769dcf16e3 R-3: W1.12: a module hears a seat's event kept on its own stream through its durable
A seat's event kept apart from its family (the node-engine seat's running, kept last per subject; mesh-delivery's owed,
a stream with an age and a cap) had no helper: EventHub binds only the shared events stream, and dev-G-engine and
dev-G-forge each met it. process.SeatStreamName is the bus's name of a contract's Stream<E> (SEAT_<seat>_<event>), one
rule for its maker and its hearers; Account.SeatEventConsumerConfig the module's durable as the maker makes it (last
per subject where the event is kept so); Account.HearSeatEvents binds and pulls it, making nothing.

Builds: design 47 G §260, §24, §39, §146, §153, §199

Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
2026-11-11 10:51:06 +01:00

53 lines
2.0 KiB
Go

package process
import (
"testing"
"github.com/nats-io/nats.go/jetstream"
)
func TestTheHubMatchesSubjectsAndRefusesOverlappingPatterns(t *testing.T) {
for _, c := range []struct {
a, b string
match, overlap bool
}{
{"mesh.mod.*.event.views.*", "mesh.mod.o.event.views.x", true, true},
{"mesh.mod.p.event.>", "mesh.mod.p.event", false, false},
{"mesh.mod.p.event.a", "mesh.mod.q.event.a", false, false},
{"mesh.mod.p.event.>", "mesh.mod.*.event.a", false, true},
{"mesh.mod.p.event.a", "mesh.mod.p.event.a.b", false, false},
} {
if got := subjectMatches(c.a, c.b); got != c.match && c.match {
t.Errorf("%s should match %s", c.a, c.b)
}
if got := subjectsOverlap(c.a, c.b); got != c.overlap {
t.Errorf("overlap(%s, %s) = %v", c.a, c.b, got)
}
}
h := NewEventHub(nil)
nop := func(jetstream.Msg) {}
if err := h.Handle("mesh.mod.p.event.>", nop); err != nil {
t.Fatal(err)
}
if err := h.Handle("mesh.mod.*.event.a", nop); err == nil {
t.Fatal("an overlapping pattern was accepted")
}
if err := h.Handle("mesh.mod.q.event.>", nop); err != nil {
t.Fatal(err)
}
// W1.12: a seat's event kept in a stream of its own is heard on one bus name and one durable, the maker's and the
// hearer's alike; an event kept last per subject is delivered from the last of each subject.
a := Account{Node: "ace", Module: "mesh-grants"}
if got := SeatStreamName("node-engine.running"); got != "SEAT_node-engine_running" {
t.Errorf("the bus's name of node-engine.running is %q", got)
}
cfg := a.SeatEventConsumerConfig([]string{"mesh.seat.node-engine.event.running.>"}, true)
if cfg.Durable != "ace_mesh-grants" || cfg.DeliverPolicy != jetstream.DeliverLastPerSubjectPolicy ||
cfg.AckPolicy != jetstream.AckExplicitPolicy || len(cfg.FilterSubjects) != 1 {
t.Errorf("the durable on a stream kept last per subject: %+v", cfg)
}
if cfg := a.SeatEventConsumerConfig(nil, false); cfg.DeliverPolicy != jetstream.DeliverAllPolicy {
t.Errorf("the durable on a stream kept with an age starts from its first message, got %v", cfg.DeliverPolicy)
}
}