Testing the events on namespace Service
parent
d516f0aaae
commit
3c12794d9c
@ -0,0 +1,38 @@
|
||||
package namespace
|
||||
|
||||
import (
|
||||
"caj-larsson/bog/util"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEventTest(t *testing.T) {
|
||||
eb := util.NewEventBus()
|
||||
svc := NamespaceService{}
|
||||
|
||||
svc.Wire(eb.Register, eb.Handle)
|
||||
|
||||
events := []util.Event{
|
||||
*util.NewEvent("FileUsed", struct {
|
||||
Name string
|
||||
Size int64
|
||||
}{
|
||||
"asd",
|
||||
int64(12),
|
||||
}),
|
||||
*util.NewEvent("FileDeleted", struct {
|
||||
Name string
|
||||
Size int64
|
||||
}{
|
||||
"asd",
|
||||
int64(12),
|
||||
}),
|
||||
*util.NewEvent("FileRecieved", struct {
|
||||
Name string
|
||||
Size int64
|
||||
}{
|
||||
"asd",
|
||||
int64(12),
|
||||
}),
|
||||
}
|
||||
util.AcceptsMessage(t, eb, events)
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/matryer/is"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func (eb *EventBus) Handled(e Event) bool {
|
||||
// TODO: figure out how to verify the event signature here.
|
||||
handlers, exists := eb.handlers[e.EventName()]
|
||||
if !exists {
|
||||
return false
|
||||
}
|
||||
|
||||
return len(handlers) > 0
|
||||
}
|
||||
|
||||
func AcceptsMessage(t *testing.T, eb *EventBus, es []Event) {
|
||||
is := is.New(t)
|
||||
for _, e := range es {
|
||||
is.True(eb.Handled(e))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue