Files
mesh-controller/internal/broker/agreement_streams_test.go
T
jschoubben 07a8f04e65
mesh/merge-gate head 07a8f04e65a3 merged into trunk a5a43c8f31f0 — pass: the change touches no module of the mesh's graph
mesh/repo-check head 07a8f04e65a3 merged into trunk a5a43c8f31f0 — pass: its merge-check.sh passed
mesh/delivery delivered
Count a module's own stream events beside its emits in the catalogue agreement (issue 1249)
2026-10-19 15:31:13 +02:00

39 lines
1.5 KiB
Go

package broker
import (
"strings"
"testing"
)
// mailShaped is mesh-mail's manifest as mesh-catalog main (b767aac8) declares its events: emits beside two streams of
// its own (modules/mesh-mail/module.json), trimmed to the keys the agreement reads.
const mailShaped = `{"module": "mesh-mail",
"emits": ["mail.send.sent", "mail.send.failed"],
"streams": [
{"name": "mail", "events": ["mail.*.message.added", "mail.*.message.changed", "mail.*.message.removed"]},
{"name": "mail-sends", "events": ["mail.send.approved"]}]}`
func TestAModulesStreamEventsCountBesideItsEmits(t *testing.T) { // 1249/AC1
emitter, _, _, err := eventsOfManifest([]byte(mailShaped))
if err != nil || emitter == nil {
t.Fatalf("emitter %v, err %v", emitter, err)
}
bad := Disagreements([]AnEmitter{*emitter},
[]AConsumer{{Module: "mesh-mail-notifier", Consumes: []string{"mesh-mail.mail.*.message.added"}}}, nil)
if len(bad) != 0 {
t.Fatalf("a consumer of mesh-mail's stream event was reported: %v", bad)
}
}
func TestAnEventNeitherEmittedNorOnTheStreamIsStillCaught(t *testing.T) { // 1249/AC2
emitter, _, _, err := eventsOfManifest([]byte(mailShaped))
if err != nil || emitter == nil {
t.Fatalf("emitter %v, err %v", emitter, err)
}
bad := Disagreements([]AnEmitter{*emitter},
[]AConsumer{{Module: "mesh-mail-notifier", Consumes: []string{"mesh-mail.mail.*.message.renamed"}}}, nil)
if len(bad) != 1 || !strings.Contains(bad[0], "mail.*.message.added") {
t.Fatalf("want one disagreement naming the stream's events among what mesh-mail emits, got %v", bad)
}
}