Backend: Add tests to internal/event
This commit is contained in:
parent
5f29c0095a
commit
c87da2f72f
3 changed files with 151 additions and 0 deletions
82
internal/event/entity_test.go
Normal file
82
internal/event/entity_test.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"github.com/leandro-lugaresi/hub"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEntitiesUpdated(t *testing.T) {
|
||||
s := Subscribe("test.updated")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
entities := "test"
|
||||
EntitiesUpdated("test", entities)
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "test.updated", msg.Name)
|
||||
assert.Equal(t, Data{"entities": "test"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestEntitiesCreated(t *testing.T) {
|
||||
s := Subscribe("test.created")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
entities := "test"
|
||||
EntitiesCreated("test", entities)
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "test.created", msg.Name)
|
||||
assert.Equal(t, Data{"entities": "test"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestEntitiesDeleted(t *testing.T) {
|
||||
s := Subscribe("test.deleted")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
entities := "test"
|
||||
EntitiesDeleted("test", entities)
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "test.deleted", msg.Name)
|
||||
assert.Equal(t, Data{"entities": "test"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestEntitiesArchived(t *testing.T) {
|
||||
s := Subscribe("test.archived")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
entities := "test"
|
||||
EntitiesArchived("test", entities)
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "test.archived", msg.Name)
|
||||
assert.Equal(t, Data{"entities": "test"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestEntitiesRestored(t *testing.T) {
|
||||
s := Subscribe("test.restored")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
entities := "test"
|
||||
EntitiesRestored("test", entities)
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "test.restored", msg.Name)
|
||||
assert.Equal(t, Data{"entities": "test"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
|
@ -29,3 +29,59 @@ func TestPublishSubscribe(t *testing.T) {
|
|||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
s := Subscribe("notify.error")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
Error("error message")
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "notify.error", msg.Name)
|
||||
assert.Equal(t, Data{"msg": "error message"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestSuccess(t *testing.T) {
|
||||
s := Subscribe("notify.success")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
Success("success message")
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "notify.success", msg.Name)
|
||||
assert.Equal(t, Data{"msg": "success message"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
s := Subscribe("notify.info")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
Info("info message")
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "notify.info", msg.Name)
|
||||
assert.Equal(t, Data{"msg": "info message"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
||||
func TestWarning(t *testing.T) {
|
||||
s := Subscribe("notify.warning")
|
||||
|
||||
assert.IsType(t, hub.Subscription{}, s)
|
||||
|
||||
Warning("warning message")
|
||||
msg := <-s.Receiver
|
||||
|
||||
assert.Equal(t, "notify.warning", msg.Name)
|
||||
assert.Equal(t, Data{"msg": "warning message"}, msg.Fields)
|
||||
|
||||
Unsubscribe(s)
|
||||
}
|
||||
|
|
13
internal/event/log_test.go
Normal file
13
internal/event/log_test.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewHook(t *testing.T) {
|
||||
hub := NewHub()
|
||||
hook := NewHook(hub)
|
||||
|
||||
assert.IsType(t, &Hook{hub: hub}, hook)
|
||||
}
|
Loading…
Reference in a new issue