diff --git a/dataswamp/namespace/service_test.go b/dataswamp/namespace/service_test.go new file mode 100644 index 0000000..1d1d31e --- /dev/null +++ b/dataswamp/namespace/service_test.go @@ -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) +} diff --git a/util/eventbus_contract.go b/util/eventbus_contract.go new file mode 100644 index 0000000..43a5678 --- /dev/null +++ b/util/eventbus_contract.go @@ -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)) + } +} diff --git a/util/logging.go b/util/logging.go index ecd0415..7195bbb 100644 --- a/util/logging.go +++ b/util/logging.go @@ -5,3 +5,9 @@ type Logger interface { Info(format string, a ...interface{}) Warn(format string, a ...interface{}) } + +type TestLogger struct{} + +func (t TestLogger) Debug(format string, a ...interface{}) {} +func (t TestLogger) Info(format string, a ...interface{}) {} +func (t TestLogger) Warn(format string, a ...interface{}) {}