Package joetest implements helpers to implement unit tests for bots.
Bot wraps a *joe.Bot for unit testing.
NewBot creates a new *Bot instance that can be used in unit tests. The Bots will use a CLIAdapter which accepts messages from the Bot.Input and write all output to Bot.Output. The logger is a zaptest.Logger which sends all logs through the passed TestingT (usually a *testing.T instance).
For ease of testing a Bot can be started and stopped without a cancel via Bot.Start() and Bot.Stop().
EmitSync emits the given event on the Brain and blocks until all registered handlers have completely processed it.
ReadOutput consumes all data from b.Output and returns it as a string so you can easily make assertions on it.
Run wraps Bot.Run() in order to allow stopping a Bot without having to inject another context.
Start executes the Bot.Run() function and stores its error result in a channel so the caller can eventually execute Bot.Stop() and receive the result. This function blocks until the event handler is actually running and emits the InitEvent.
Stop stops a running Bot and blocks until it has completed. If Bot.Run() returned an error it is passed to the Errorf function of the TestingT that was used to create the Bot.
Brain wraps the joe.Brain for unit testing.
NewBrain creates a new Brain that can be used for unit testing. The Brain registers to all events except the (init and shutdown event) and records them for later access. The event handling loop of the Brain (i.e. Brain.HandleEvents()) is automatically started by this function in a new goroutine and the caller must call Brain.Finish() at the end of their tests.
Events returns a channel that receives all emitted events.
Finish stops the event handler loop of the Brain and waits until all pending events have been processed.
RecordedEvents returns all events the Brain has processed except the joe.InitEvent and joe.ShutdownEvent.
Storage wraps a joe.Storage for unit testing purposes.
NewStorage creates a new Storage.
AssertEquals checks that the actual value under the given key equals an expected value.
MustSet assigns the value to the given key and fails the test immediately if there was an error.
TestingT is the minimum required subset of the testing API used in the joetest package. TestingT is implemented both by *testing.T and *testing.B.