Add more tests.

This commit is contained in:
Joachim Bauch 2021-06-04 15:30:55 +02:00
parent 762d1512c4
commit 1687c80122
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
2 changed files with 82 additions and 0 deletions

View File

@ -63,3 +63,27 @@ func TestLoopbackNatsClient_Subscribe(t *testing.T) {
testNatsClient_Subscribe(t, client)
})
}
func TestLoopbackClient_PublishAfterClose(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client := CreateLoopbackNatsClientForTest(t)
testNatsClient_PublishAfterClose(t, client)
})
}
func TestLoopbackClient_SubscribeAfterClose(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client := CreateLoopbackNatsClientForTest(t)
testNatsClient_SubscribeAfterClose(t, client)
})
}
func TestLoopbackClient_BadSubjects(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client := CreateLoopbackNatsClientForTest(t)
testNatsClient_BadSubjects(t, client)
})
}

View File

@ -109,3 +109,61 @@ func TestNatsClient_Subscribe(t *testing.T) {
testNatsClient_Subscribe(t, client)
})
}
func testNatsClient_PublishAfterClose(t *testing.T, client NatsClient) {
client.Close()
if err := client.Publish("foo", "bar"); err != nats.ErrConnectionClosed {
t.Errorf("Expected %v, got %v", nats.ErrConnectionClosed, err)
}
}
func TestNatsClient_PublishAfterClose(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client, shutdown := CreateLocalNatsClientForTest(t)
defer shutdown()
testNatsClient_PublishAfterClose(t, client)
})
}
func testNatsClient_SubscribeAfterClose(t *testing.T, client NatsClient) {
client.Close()
ch := make(chan *nats.Msg)
if _, err := client.Subscribe("foo", ch); err != nats.ErrConnectionClosed {
t.Errorf("Expected %v, got %v", nats.ErrConnectionClosed, err)
}
}
func TestNatsClient_SubscribeAfterClose(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client, shutdown := CreateLocalNatsClientForTest(t)
defer shutdown()
testNatsClient_SubscribeAfterClose(t, client)
})
}
func testNatsClient_BadSubjects(t *testing.T, client NatsClient) {
subjects := []string{
"foo bar",
"foo.",
}
ch := make(chan *nats.Msg)
for _, s := range subjects {
if _, err := client.Subscribe(s, ch); err != nats.ErrBadSubject {
t.Errorf("Expected %v for subject %s, got %v", nats.ErrBadSubject, s, err)
}
}
}
func TestNatsClient_BadSubjects(t *testing.T) {
ensureNoGoroutinesLeak(t, func() {
client, shutdown := CreateLocalNatsClientForTest(t)
defer shutdown()
testNatsClient_BadSubjects(t, client)
})
}