diff --git a/pkg/events/nats/nats_producer_test.go b/pkg/events/nats/nats_producer_test.go index d6013c9..272fd68 100644 --- a/pkg/events/nats/nats_producer_test.go +++ b/pkg/events/nats/nats_producer_test.go @@ -3,14 +3,29 @@ package nats_producer import "testing" func TestNewNatsProducerDoesNotConnectWithoutURL(t *testing.T) { - producer, ok := NewNatsProducer(" ", false, nil, nil).(*natsProducer) - if !ok { - t.Fatal("constructor returned an unexpected producer type") + tests := []struct { + name string + url string + }{ + {"Empty URL", ""}, + {"Whitespace URL", " "}, } - if producer.conn != nil { - t.Fatal("NATS connection must stay nil when NATS_URL is empty") - } - if producer.natsGlobalEnabled { - t.Fatal("NATS global publishing must stay disabled without a URL") + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + producer, ok := NewNatsProducer(tt.url, true, []string{"event1"}, nil).(*natsProducer) + if !ok { + t.Fatal("constructor returned an unexpected producer type") + } + if producer.conn != nil { + t.Fatal("NATS connection must stay nil when NATS_URL is empty") + } + if producer.natsGlobalEnabled { + t.Fatal("NATS global publishing must stay disabled without a URL") + } + if producer.natsGlobalEvents != nil { + t.Fatal("natsGlobalEvents must be nil when NATS_URL is empty") + } + }) } }