MCPcopy
hub / github.com/nats-io/nats.go / TestJetStreamBindConsumer

Function TestJetStreamBindConsumer

test/js_test.go:8785–8965  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8783}
8784
8785func TestJetStreamBindConsumer(t *testing.T) {
8786 s := RunBasicJetStreamServer()
8787 defer shutdownJSServerAndRemoveStorage(t, s)
8788
8789 nc, js := jsClient(t, s)
8790 defer nc.Close()
8791
8792 if _, err := js.AddStream(nil); err == nil {
8793 t.Fatalf("Unexpected success")
8794 }
8795 si, err := js.AddStream(&nats.StreamConfig{Name: "foo"})
8796 if err != nil {
8797 t.Fatalf("Unexpected error: %v", err)
8798 }
8799 if si == nil || si.Config.Name != "foo" {
8800 t.Fatalf("StreamInfo is not correct %+v", si)
8801 }
8802
8803 for i := 0; i < 25; i++ {
8804 js.Publish("foo", []byte("hi"))
8805 }
8806
8807 // Both stream and consumer names are required for bind only.
8808 _, err = js.SubscribeSync("foo", nats.Bind("", ""))
8809 if err != nats.ErrStreamNameRequired {
8810 t.Fatalf("Unexpected error: %v", err)
8811 }
8812 _, err = js.SubscribeSync("foo", nats.Bind("foo", ""))
8813 if err != nats.ErrConsumerNameRequired {
8814 t.Fatalf("Unexpected error: %v", err)
8815 }
8816 _, err = js.SubscribeSync("foo", nats.Bind("foo", "push"))
8817 if err == nil || !errors.Is(err, nats.ErrConsumerNotFound) {
8818 t.Fatalf("Unexpected error: %v", err)
8819 }
8820
8821 // Pull consumer
8822 _, err = js.PullSubscribe("foo", "pull", nats.Bind("foo", "pull"))
8823 if err == nil || !errors.Is(err, nats.ErrConsumerNotFound) {
8824 t.Fatalf("Unexpected error: %v", err)
8825 }
8826
8827 // Push consumer
8828 _, err = js.AddConsumer("foo", &nats.ConsumerConfig{
8829 Durable: "push",
8830 AckPolicy: nats.AckExplicitPolicy,
8831 DeliverSubject: nats.NewInbox(),
8832 })
8833 if err != nil {
8834 t.Fatalf("Unexpected error: %v", err)
8835 }
8836
8837 // Push Consumer Bind Only
8838 sub, err := js.SubscribeSync("foo", nats.Bind("foo", "push"))
8839 if err != nil {
8840 t.Fatal(err)
8841 }
8842 // Ambiguous declaration should not be allowed.

Callers

nothing calls this directly

Calls 15

FatalfMethod · 0.80
NewInboxMethod · 0.80
UnsubscribeMethod · 0.80
ErrorfMethod · 0.80
NextMsgMethod · 0.80
AckSyncMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
checkForFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected