preflight

package
v2.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Scaffold *scaffold

Scaffold a set of functions that may be replaced for testing

Functions

func Restore

func Restore()

Restore restores the scaffold to its default state

Types

type Action

type Action func()

Action is a function with no arguments

type Expectation

type Expectation interface {
	// Sugar
	To() Expectation
	Be() Expectation
	Is() Expectation
	Should() Expectation

	// Negation
	Not() Expectation

	// Assertions
	Nil()
	True()
	False()
	Empty()
	HasLength(expected int)
	HaveLength(expected int)
	Equal(expected interface{})
	Equals(expected interface{})
	EqualTo(expected interface{})
	Match(pattern string)
	Matches(pattern string)
}

Expectation represents an expectation about a value or behavior

func ExpectValue

func ExpectValue(t *testing.T, actual interface{}) Expectation

ExpectValue returns a new value-based Expectation

type FileConsumer

type FileConsumer func(file *os.File)

FileConsumer is a function that consumes a file

type LogExpectation

type LogExpectation struct {
	Time     Expectation
	Name     Expectation
	Level    Expectation
	Fields   Expectation
	Message  Expectation
	FullText Expectation
}

LogExpectation is a set of expectations based on parsed logs

func ExpectLog

func ExpectLog(t *testing.T, text string) *LogExpectation

ExpectLog creates a new LogExpectation

type LogsConsumer

type LogsConsumer func(stdout *os.File, stderr *os.File)

LogsConsumer is a function that consumes two streams

type Negation

type Negation struct {
	*testing.T

	Actual  interface{}
	Inverse Expectation
}

Negation is a negated expectation

func (*Negation) Be

func (not *Negation) Be() Expectation

Be returns the current expectation

func (*Negation) Empty

func (not *Negation) Empty()

Empty asserts the value is an array with length != 0

func (*Negation) Equal

func (not *Negation) Equal(given interface{})

Equal is equivalent to Equals()

func (*Negation) EqualTo

func (not *Negation) EqualTo(given interface{})

EqualTo is equivalent to Equals()

func (*Negation) Equals

func (not *Negation) Equals(given interface{})

Equals asserts inequality to a given value

func (*Negation) False

func (not *Negation) False()

False asserts the value is false

func (*Negation) HasLength

func (not *Negation) HasLength(given int)

HasLength asserts the value is an array with length != given

func (*Negation) HaveLength

func (not *Negation) HaveLength(given int)

HaveLength is equivalent to HasLength()

func (*Negation) Is

func (not *Negation) Is() Expectation

Is returns the current expectation

func (*Negation) Match

func (not *Negation) Match(pattern string)

Match is equivalent to Matches()

func (*Negation) Matches

func (not *Negation) Matches(pattern string)

Matches asserts the value does not match a pattern

func (*Negation) Nil

func (not *Negation) Nil()

Nil asserts the value is not nil

func (*Negation) Not

func (not *Negation) Not() Expectation

Not returns a negation of the current expectation

func (*Negation) Should

func (not *Negation) Should() Expectation

Should returns the current expectation

func (*Negation) To

func (not *Negation) To() Expectation

To returns the current expectation

func (*Negation) True

func (not *Negation) True()

True asserts the value is true

type Transformation

type Transformation func(interface{}) interface{}

Transformation is a function that modifies the thing under test

type UnitTest

type UnitTest struct {
	*testing.T
}

UnitTest provides utilities for unit testing

func Unit

func Unit(t *testing.T) *UnitTest

Unit returns a new unit test

func (*UnitTest) CaptureLogs

func (unit *UnitTest) CaptureLogs(consumer LogsConsumer) (stdout []*LogExpectation, stderr []*LogExpectation)

CaptureLogs creates a list of expectations from logs

func (*UnitTest) Expect

func (unit *UnitTest) Expect(actual interface{}) Expectation

Expect returns a new value-based expectation

func (*UnitTest) ExpectExitCode

func (unit *UnitTest) ExpectExitCode(act Action) Expectation

ExpectExitCode overrides the scaffolding osExit function

func (*UnitTest) ExpectFile

func (unit *UnitTest) ExpectFile(file *os.File) Expectation

ExpectFile returns expectations based on file contents

func (*UnitTest) ExpectOutput

func (unit *UnitTest) ExpectOutput(consumer FileConsumer) Expectation

ExpectOutput returns a new output file-based expectation

type ValueExpectation

type ValueExpectation struct {
	*testing.T

	Actual interface{}
}

ValueExpectation is an expectation based on a realized value

func (*ValueExpectation) Be

func (e *ValueExpectation) Be() Expectation

Be returns the current expectation

func (*ValueExpectation) Empty

func (e *ValueExpectation) Empty()

Empty asserts the value has length 0

func (*ValueExpectation) Equal

func (e *ValueExpectation) Equal(expected interface{})

Equal is equivalent to Equals()

func (*ValueExpectation) EqualTo

func (e *ValueExpectation) EqualTo(expected interface{})

EqualTo is equivalent to Equals()

func (*ValueExpectation) Equals

func (e *ValueExpectation) Equals(expected interface{})

Equals asserts equality to an expected value

func (*ValueExpectation) False

func (e *ValueExpectation) False()

False asserts the value is false

func (*ValueExpectation) HasLength

func (e *ValueExpectation) HasLength(expected int)

HasLength asserts the value is an array with a given length

func (*ValueExpectation) HaveLength

func (e *ValueExpectation) HaveLength(expected int)

HaveLength is equivalent to HasLength()

func (*ValueExpectation) Is

func (e *ValueExpectation) Is() Expectation

Is returns the current expectation

func (*ValueExpectation) Match

func (e *ValueExpectation) Match(pattern string)

Match is equivalent to Matches()

func (*ValueExpectation) Matches

func (e *ValueExpectation) Matches(pattern string)

Matches asserts the value matches a pattern

func (*ValueExpectation) Nil

func (e *ValueExpectation) Nil()

Nil asserts the value is nil

func (*ValueExpectation) Not

func (e *ValueExpectation) Not() Expectation

Not returns a negation of the current expectation

func (*ValueExpectation) Should

func (e *ValueExpectation) Should() Expectation

Should returns the current expectation

func (*ValueExpectation) To

func (e *ValueExpectation) To() Expectation

To returns the current expectation

func (*ValueExpectation) True

func (e *ValueExpectation) True()

True asserts the value is true

Jump to

Keyboard shortcuts

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