Skip to content

Commit

Permalink
Merge pull request #795 from nats-io/add_stream_cons_desc
Browse files Browse the repository at this point in the history
[ADDED] Description in StreamConfig and ConsumerConfig
  • Loading branch information
kozlovic committed Aug 17, 2021
2 parents 78b4cc2 + 73d14e1 commit 12b9459
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions js.go
Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions jsm.go
Expand Up @@ -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"`
Expand Down
46 changes: 46 additions & 0 deletions test/js_test.go
Expand Up @@ -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)
}
}

0 comments on commit 12b9459

Please sign in to comment.