Release v1.0.0 #2
@ -2,6 +2,7 @@ package stonecqrs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
@ -49,6 +50,30 @@ func (handler *testEventHandler) Handle(
|
||||
return nil
|
||||
}
|
||||
|
||||
type testErrorHandler struct{}
|
||||
|
||||
func (handler *testErrorHandler) Handle(
|
||||
ctx context.Context, cmd Command,
|
||||
) ([]Event, error) {
|
||||
return nil, errors.New("test error")
|
||||
}
|
||||
|
||||
type testErrorQueryHandler struct{}
|
||||
|
||||
func (handler *testErrorQueryHandler) Handle(
|
||||
ctx context.Context, query Query,
|
||||
) (interface{}, error) {
|
||||
return nil, errors.New("test error")
|
||||
}
|
||||
|
||||
type testErrorEventHandler struct{}
|
||||
|
||||
func (handler *testErrorEventHandler) Handle(
|
||||
ctx context.Context, event Event,
|
||||
) error {
|
||||
return errors.New("test error")
|
||||
}
|
||||
|
||||
func Test_NewDispatcher(t *testing.T) {
|
||||
d := NewDispatcher()
|
||||
if d == nil {
|
||||
@ -98,7 +123,7 @@ func Test_UnknownEvent(t *testing.T) {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
err = d.DispatchEvent(context.Background(), unknownEvent{})
|
||||
_, err = d.DispatchQuery(context.Background(), unknownEvent{})
|
||||
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
@ -110,3 +135,25 @@ func Test_UnknownEvent(t *testing.T) {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Error(t *testing.T) {
|
||||
d := NewDispatcher()
|
||||
d.RegisterCommandHandler(testCommand{}, &testErrorHandler{})
|
||||
d.RegisterQueryHandler(testQuery{}, &testErrorQueryHandler{})
|
||||
d.RegisterEventHandler(testEvent{}, &testErrorEventHandler{})
|
||||
|
||||
_, err := d.DispatchCommand(context.Background(), testCommand{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
_, err = d.DispatchQuery(context.Background(), testQuery{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
|
||||
err = d.DispatchEvent(context.Background(), testEvent{})
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user