Documentation
¶
Overview ¶
Package joetest implements helpers to implement unit tests for bots.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct { *joe.Bot T TestingT Input io.Writer Output io.Reader // contains filtered or unexported fields }
Bot wraps a *joe.Bot for unit testing.
func NewBot ¶
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().
func (*Bot) EmitSync ¶
func (b *Bot) EmitSync(event interface{})
EmitSync emits the given event on the Brain and blocks until all registered handlers have completely processed it.
func (*Bot) Run ¶
Run wraps Bot.Run() in order to allow stopping a Bot without having to inject another context.
type Brain ¶
Brain wraps the joe.Brain for unit testing.
func NewBrain ¶
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.
func (*Brain) Finish ¶
func (b *Brain) Finish()
Finish stops the event handler loop of the Brain and waits until all pending events have been processed.
func (*Brain) RecordedEvents ¶
func (b *Brain) RecordedEvents() []interface{}
RecordedEvents returns all events the Brain has processed except the joe.InitEvent and joe.ShutdownEvent.
type TestingT ¶
type TestingT interface { Logf(string, ...interface{}) Errorf(string, ...interface{}) Fail() Failed() bool Name() string FailNow() Helper() }
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.