joetest

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

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

func NewBot(t TestingT, modules ...joe.Module) *Bot

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

func (b *Bot) Run() error

Run wraps Bot.Run() in order to allow stopping a Bot without having to inject another context.

func (*Bot) Start

func (b *Bot) Start()

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.

func (*Bot) Stop

func (b *Bot) Stop()

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.

type Brain

type Brain struct {
	*joe.Brain
	// contains filtered or unexported fields
}

Brain wraps the joe.Brain for unit testing.

func NewBrain

func NewBrain(t TestingT) *Brain

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) Events

func (b *Brain) Events() <-chan joe.Event

Events returns a channel that receives all emitted events.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL