6
0
mirror of https://git.mills.io/prologic/msgbus.git synced 2024-06-26 00:38:55 +00:00
prologic-msgbus/client/client_test.go

34 lines
668 B
Go
Raw Normal View History

2018-05-15 06:59:01 +00:00
package client
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/prologic/msgbus"
)
func TestClientPublish(t *testing.T) {
assert := assert.New(t)
mb := msgbus.New(nil)
server := httptest.NewServer(mb)
defer server.Close()
client := NewClient(server.URL, nil)
err := client.Publish("hello", "hello world")
assert.NoError(err)
topic := mb.NewTopic("hello")
expected := msgbus.Message{Topic: topic, Payload: []byte("hello world")}
actual, ok := mb.Get(topic)
assert.True(ok)
assert.Equal(actual.ID, expected.ID)
assert.Equal(actual.Topic, expected.Topic)
assert.Equal(actual.Payload, expected.Payload)
}