package broker import ( "testing" "github.com/novox/mesh-controller/internal/testbus" ) // Against a real server, because the questions here are all "does the server accept this" — // which a mock would answer by agreeing with whatever this file already believes. // // Skipped unless MESH_TEST_NATS names one, so the ordinary suite stays fast and offline: // // go test ./internal/broker/ -run TestAgainstARealServer (each test on a bus of its own: internal/testbus) func TestAgainstARealServer(t *testing.T) { url := testbus.URL(t) js, err := Dial(url) if err != nil { t.Fatal(err) } defer js.Close() t.Run("the mesh's own streams are accepted", func(t *testing.T) { if err := AssertMeshStreams(js); err != nil { t.Fatal(err) } }) t.Run("asserting again changes nothing and fails nothing", func(t *testing.T) { if err := AssertMeshStreams(js); err != nil { t.Fatalf("the second assertion failed, so the controller cannot restart: %v", err) } }) t.Run("a seat's work queue is accepted beside them", func(t *testing.T) { seats := []DeclaredSeat{{Name: "telegram-sender", Accepts: []string{"send"}}} for _, s := range SeatStreams(seats) { if err := js.EnsureStream(s); err != nil { t.Fatal(err) } } if c := AllOverlaps(seats); len(c) != 0 { t.Fatalf("overlaps the server would refuse: %v", c) } }) t.Run("a module's consumer is accepted and is idempotent", func(t *testing.T) { c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "one", Module: "audit", Consumes: []string{"shop.order.placed", "billing.invoice.sent"}, PasswordHash: "x"}) if !ok { t.Fatal("no consumer derived") } if err := js.EnsureConsumer(c); err != nil { t.Fatal(err) } if err := js.EnsureConsumer(c); err != nil { t.Fatalf("the second assertion failed: %v", err) } }) t.Run("a holder's worker is accepted with its queue group", func(t *testing.T) { c, _ := HolderConsumerFor("one", "telegram", DeclaredSeat{Name: "telegram-sender", Accepts: []string{"send"}}) if err := js.EnsureConsumer(c); err != nil { t.Fatal(err) } }) }