expect

package module
Version: v0.0.0-...-e1f779c Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2020 License: LGPL-3.0 Imports: 5 Imported by: 0

README

expect

Moved to gitlab.com/akabio/expect

Go test expectations.

Intention of the library is to be able to write simple readable tests which produce easy to understand messages when the expectation fails.

func TestExample(t *testing.T) {
    expect.Value(t, "the guy", "Peter").ToBe("Steven")
    // will fail with error:
    //   expected the guy to be 'Steven' but it is 'Peter'
}

Expectations

ToBe

Asserts that the value is deeply equal to the provided value.

expect.Value(t, "the house", "big").ToBe("small")
// expected the house to be 'small' but it is 'big'

It will print complex data types formated as yaml:

expect.Value(t, "array", []int{3, 1}).ToBe([]int{1, 3})
// expected array to be:
//   > - 1
//   > - 3
// but it is:
//   > - 3
//   > - 1

It will check for exact numbers:

expect.Value(t, "liters", 3.4500000000001).ToBe(3.45)
// expected liters to be 3.45 but it is 3.4500000000001
ToCount

Asserts that the list/map/chan/string has c elements.

expect.Value(t, "token", "F7gTr7y").ToCount(8)
// expected token to have 8 elements but it has 7 elements
ToHavePrefix

Asserts that the string begins with the provided string.

NotToBe

Asserts that the value is not deeply equal to the provided value.

ToBeAbout

Asserts that the number is about expected value with a margib of error of provided delta.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColoredDiffOutput = output("coloredDiffOutput")
View Source
var Output = PlainOutput
View Source
var PlainOutput = output("plain")

Functions

This section is empty.

Types

type Test

type Test interface {
	Fatalf(f string, i ...interface{})
	Errorf(f string, i ...interface{})
	Error(p ...interface{})
}

Test implements testing.T methods used by expect. Necessary to: - allow usage of testing.T and testing.B instances - for running tests

type Val

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

Val to call expectations on.

func Value

func Value(t Test, name string, val interface{}) Val

Value wraps a value and provides expectations for this value.

func (Val) NotToBe

func (e Val) NotToBe(unExpected interface{}) Val

NotToBe asserts that the value is not deeply equals to expected value.

func (Val) ToBe

func (e Val) ToBe(expected interface{}) Val

ToBe asserts that the value is deeply equals to expected value.

func (Val) ToBeAbout

func (e Val) ToBeAbout(expected, delta float64) Val

ToBeAbout asserts that the number is in deltas range of expected value. Only works for numbers.

func (Val) ToCount

func (e Val) ToCount(c int) Val

ToCount asserts that the list/map/chan/string has c elements.

func (Val) ToHavePrefix

func (e Val) ToHavePrefix(prefix string) Val

ToHavePrefix asserts that the string value starts with the provided prefix.

func (Val) ToHaveSuffix

func (e Val) ToHaveSuffix(suffix string) Val

ToHaveSuffix asserts that the string value ends with the provided sufix.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL