testutils

package
v0.0.0-...-c6f7f91 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFreePort

func FindFreePort(t *testing.T, host string, maxAttempts int) (int, error)

FindFreePort attempts to find an unused tcp port

Types

type Expectation

type Expectation interface {
	IsMatch(line string) bool
	String() string
}

type LogHarness

type LogHarness struct {
	// contains filtered or unexported fields
}

A LogHarness runs sets of assertions against the log output of a function. Assertions are grouped into sequences of messages that are expected to be found in the log output. Calling one of the Expect methods on the harness adds an expectation to the default sequence of messages. Additional sequences can be created by calling NewSequence.

func (*LogHarness) Expect

func (h *LogHarness) Expect(s string)

Expect adds an expectation to the default sequence that the log contains a line equal to s

func (*LogHarness) ExpectPrefix

func (h *LogHarness) ExpectPrefix(s string)

ExpectPrefix adds an to the default sequence expectation that the log contains a line starting with s

func (*LogHarness) NewSequence

func (h *LogHarness) NewSequence(name string) *Sequence

NewSequence creates a new sequence of expected log messages

func (*LogHarness) Run

func (h *LogHarness) Run(t *testing.T, f func())

Run executes the function f and captures any output written using Go's standard log. Each sequence of expected messages is then

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

func (*Sequence) Assert

func (seq *Sequence) Assert(t *testing.T, s *bufio.Scanner)

func (*Sequence) Expect

func (seq *Sequence) Expect(s string)

Expect adds an expectation that the log contains a line equal to s

func (*Sequence) ExpectPrefix

func (seq *Sequence) ExpectPrefix(s string)

ExpectPrefix adds an expectation that the log contains a line starting with s

Jump to

Keyboard shortcuts

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