2019-11-16 16:06:34 +01:00
|
|
|
package event
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/leandro-lugaresi/hub"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSharedHub(t *testing.T) {
|
|
|
|
h := SharedHub()
|
|
|
|
|
|
|
|
assert.IsType(t, &hub.Hub{}, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPublishSubscribe(t *testing.T) {
|
|
|
|
s := Subscribe("foo.bar")
|
|
|
|
|
|
|
|
assert.IsType(t, hub.Subscription{}, s)
|
|
|
|
|
|
|
|
Publish("foo.bar", Data{"id": 13})
|
|
|
|
|
|
|
|
msg := <-s.Receiver
|
|
|
|
|
2019-12-11 14:10:20 +01:00
|
|
|
t.Logf("receive msg with topic %s: %v\n", msg.Name, msg.Fields)
|
2019-11-16 16:06:34 +01:00
|
|
|
|
|
|
|
assert.Equal(t, "foo.bar", msg.Name)
|
|
|
|
assert.Equal(t, Data{"id": 13}, msg.Fields)
|
|
|
|
|
|
|
|
Unsubscribe(s)
|
|
|
|
}
|