package bus import "testing" // novox/hq ADR 0363 §2, §3: an event goes to the stream whose pattern carries it, as the bus matches subjects. func TestAnEventFallsUnderAStreamsPatternAsTheBusMatchesIt(t *testing.T) { for _, c := range []struct { pattern, event string want bool }{ {"mail.*.message.added", "mail.home.message.added", true}, {"mail.*.message.added", "mail.home.message.removed", false}, {"mail.*.message.added", "mail.home.work.message.added", false}, {"mail.>", "mail.home.message.added", true}, {"mail.**", "mail.home", true}, {"mail.>", "mail", false}, {"status", "status", true}, {"status", "status.changed", false}, {"", "status", false}, } { if got := eventMatches(c.pattern, c.event); got != c.want { t.Errorf("%q under %q: %v, want %v", c.event, c.pattern, got, c.want) } } } // A membership naming no stream publishes every event on EVENTS, exactly as before (issue 725). func TestAnEventNoStreamCarriesIsPublishedOnEvents(t *testing.T) { mail := &Membership{Module: "mail", Streams: []StreamIssued{{Stream: "MAIL", Events: []string{"mail.*.message.added"}, Subject: "mesh.stream.mail.event.{event}"}}} for _, c := range []struct { m *Membership event string want string }{ {nil, "mail.home.message.added", "mesh.mod.mail.event.mail.home.message.added"}, {&Membership{Module: "mail"}, "mail.home.message.added", "mesh.mod.mail.event.mail.home.message.added"}, {mail, "mail.home.message.added", "mesh.stream.mail.event.mail.home.message.added"}, {mail, "status", "mesh.mod.mail.event.status"}, } { if got := eventSubject(c.m, "mail", c.event); got != c.want { t.Errorf("%s: %s, want %s", c.event, got, c.want) } } if got := keyOf("mesh.stream.mail.event.mail.home.message.added"); got != "mail.mail.home.message.added" { t.Errorf("a stream's event reaches its consumer as %q, not as on EVENTS", got) } }