From 73d14e17c529e19a4461f66d10e62984c1271eaa Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Mon, 16 Aug 2021 19:20:42 -0600 Subject: [PATCH] [ADDED] Description in StreamConfig and ConsumerConfig Signed-off-by: Ivan Kozlovic --- js.go | 1 + jsm.go | 1 + test/js_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/js.go b/js.go index 92b6e5449..34389d098 100644 --- a/js.go +++ b/js.go @@ -772,6 +772,7 @@ func Context(ctx context.Context) ContextOpt { // ConsumerConfig is the configuration of a JetStream consumer. type ConsumerConfig struct { Durable string `json:"durable_name,omitempty"` + Description string `json:"description,omitempty"` DeliverSubject string `json:"deliver_subject,omitempty"` DeliverGroup string `json:"deliver_group,omitempty"` DeliverPolicy DeliverPolicy `json:"deliver_policy"` diff --git a/jsm.go b/jsm.go index 00ea173a8..f40086b29 100644 --- a/jsm.go +++ b/jsm.go @@ -75,6 +75,7 @@ type JetStreamManager interface { // given the name will be used as the only subject. type StreamConfig struct { Name string `json:"name"` + Description string `json:"description,omitempty"` Subjects []string `json:"subjects,omitempty"` Retention RetentionPolicy `json:"retention"` MaxConsumers int `json:"max_consumers"` diff --git a/test/js_test.go b/test/js_test.go index 619dca410..660029d04 100644 --- a/test/js_test.go +++ b/test/js_test.go @@ -5915,3 +5915,49 @@ func TestJetStreamDomainInPubAck(t *testing.T) { t.Fatalf("Expected PubAck to have domain of %q, got %q", "HUB", pa.Domain) } } + +func TestJetStreamStreamAndConsumerDescription(t *testing.T) { + s := RunBasicJetStreamServer() + defer s.Shutdown() + + if config := s.JetStreamConfig(); config != nil { + defer os.RemoveAll(config.StoreDir) + } + + nc, err := nats.Connect(s.ClientURL()) + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + defer nc.Close() + + js, err := nc.JetStream() + if err != nil { + t.Fatalf("Unexpected error: %v", err) + } + + streamDesc := "stream description" + si, err := js.AddStream(&nats.StreamConfig{ + Name: "TEST", + Description: streamDesc, + Subjects: []string{"foo"}, + }) + if err != nil { + t.Fatalf("Error adding stream: %v", err) + } + if si.Config.Description != streamDesc { + t.Fatalf("Invalid description: %q vs %q", streamDesc, si.Config.Description) + } + + consDesc := "consumer description" + ci, err := js.AddConsumer("TEST", &nats.ConsumerConfig{ + Description: consDesc, + Durable: "dur", + DeliverSubject: "bar", + }) + if err != nil { + t.Fatalf("Error adding consumer: %v", err) + } + if ci.Config.Description != consDesc { + t.Fatalf("Invalid description: %q vs %q", consDesc, ci.Config.Description) + } +}