test(nats): refactor tests and add global events state assertion
(cherry picked from commit 1860110296ea775734752be8a40b93726c34ff27)
This commit is contained in:
1 parent
a4add7cc5e
commit
a0c74485b8
1 file changed
+23
-8
@@ -3,14 +3,29 @@ package nats_producer
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestNewNatsProducerDoesNotConnectWithoutURL(t *testing.T) {
|
func TestNewNatsProducerDoesNotConnectWithoutURL(t *testing.T) {
|
||||||
producer, ok := NewNatsProducer(" ", false, nil, nil).(*natsProducer)
|
tests := []struct {
|
||||||
if !ok {
|
name string
|
||||||
t.Fatal("constructor returned an unexpected producer type")
|
url string
|
||||||
|
}{
|
||||||
|
{"Empty URL", ""},
|
||||||
|
{"Whitespace URL", " "},
|
||||||
}
|
}
|
||||||
if producer.conn != nil {
|
|
||||||
t.Fatal("NATS connection must stay nil when NATS_URL is empty")
|
for _, tt := range tests {
|
||||||
}
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
if producer.natsGlobalEnabled {
|
producer, ok := NewNatsProducer(tt.url, true, []string{"event1"}, nil).(*natsProducer)
|
||||||
t.Fatal("NATS global publishing must stay disabled without a URL")
|
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")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user