2018-05-15 06:59:01 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2021-07-12 21:57:54 +00:00
|
|
|
"git.mills.io/prologic/msgbus"
|
2018-05-15 06:59:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|