modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

Testing setup #8

Closed bounoable closed 1 year ago

bounoable commented 3 years ago

Command Bus testing

This is tedious:

package foo_test

func TestSomethingWithCommandBus(t *testing.T) {
    ereg := event.NewRegistry()
    ebus := eventstore.WithBus(chanbus.New(), ebus)
    estore := memstore.New()
    creg := command.NewRegistry()
    cbus := cmdbus.New(creg, ereg, ebus, estore)

    err := cbus.Dispatch(...)
}

Something like this should be possible:

package foo_test

func TestSomethingWithCommandBus(t *testing.T)  {
    setup := test.Setup(t)

    cbus := setup.CommandBus()

    err := cbus.Dispatch(...)
}

Command dispatches should be synchronous by default when using test.Setup:

package foo_test

func TestAsyncDispatch(t *testing.T) {
    setup := test.Setup(t)

    cbus := setup.CommandBus(dispatch.Asynchronous) // pass default dispatch options

    err := cbus.Dispatch(...)
}
bounoable commented 1 year ago

Not well thought out. Need more data