test

package module
v0.0.0-...-1845b74 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: GPL-3.0 Imports: 6 Imported by: 0

README

pipeline status coverage report

Coverage Report

Test

A test utility library.

Why?

While there are other test libraries, this test library aims to reduce boiler-plate code often used when writing tests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assert

type Assert interface {
	// Assert whether a particular value matches an expected value. If the two values
	// do not match, then the resulting error message contains a difference between the values.
	Equal(expected interface{}, actual interface{})

	// Assert that two values are not equal. If the two values are equal the test fails.
	NotEqual(expected interface{}, actual interface{})

	// Assert that an slice is of a particular length.
	Length(expected []interface{}, length uint)

	// Fail a test with a particular message.
	Fail(message string)

	// Fail a test with a particular formatter message.
	Failf(format string, args ...interface{})

	// Assert that a string begins with prefix.
	StartsWith(expectedPrefix string, s string)

	// Assert that a string is empty.
	EmptyString(s string)

	//Assert that a string is not an empty string. An empty string is a zero-length string or a string
	// with only white space
	NotEmptyString(s string)

	// NoError asserts that an error did not happen.
	NoError(error)

	// Error asserts that an error should happen. Assumes the last value is the error.
	Error(i ...interface{})

	// Assert that a boolean is true.
	True(b bool)

	// Assert that a boolean is false.
	False(b bool)

	// Assert that a particular value is not nil
	NotNil(i interface{})

	// Assert that a particular value is nil
	Nil(i interface{})

	// Assert that a string begins with a string
	HasPrefix(str string, prefix string)

	// Assert that a string ends with a string
	HasSuffix(str string, suffix string)

	// StringContains checks for whether a one string is a substring of another
	StringContains(expected string, subject string)

	// Empty check for whether a value implements the Value interface, which is used to test for Emptiness and is
	// deemed empty.
	Empty(i interface{})

	// NotEmpty asserts whether a value implements the Value interface, which is used to test for Emptiness and
	// not deemed empty.
	NotEmpty(i interface{})
}

Assert is an interface that provides functions for making assert statements.

func NewAssert

func NewAssert(t *testing.T) Assert

NewAssert creates a new assert helper struct that can be used in tests. Avoids the need to write if statements to determine if a particular value matches an expected value. Must pass in the test structure so that comparison operations can trigger test failures.

type AssertBase

type AssertBase struct {
	T *testing.T
}

AssertBase is the structure containing the assert state.

func (*AssertBase) Empty

func (assert *AssertBase) Empty(i interface{})

Empty checks for whether a value implements the empty.Value interface and that Empty method returns true.

func (*AssertBase) EmptyString

func (assert *AssertBase) EmptyString(s string)

EmptyString asserts that a string is empty

func (*AssertBase) Equal

func (assert *AssertBase) Equal(expected interface{}, actual interface{})

Equal asserts that two values are equal.

func (*AssertBase) Error

func (assert *AssertBase) Error(i ...interface{})

func (*AssertBase) Fail

func (assert *AssertBase) Fail(message string)

Fail unconditionally fails a test with a message.

func (*AssertBase) Failf

func (assert *AssertBase) Failf(format string, args ...interface{})

Failf unconditionally fails a test with a formatted message.

func (*AssertBase) False

func (assert *AssertBase) False(b bool)

False checks for whether the boolean value b is false.

func (*AssertBase) HasPrefix

func (assert *AssertBase) HasPrefix(str string, prefix string)

HasPrefix asserts that a string begins with another string

func (*AssertBase) HasSuffix

func (assert *AssertBase) HasSuffix(str string, suffix string)

HasSuffix asserts that a string ends with another string

func (*AssertBase) Length

func (assert *AssertBase) Length(expected []interface{}, length uint)

Length asserts that a particular slice or array is of a particular length.

func (*AssertBase) Nil

func (assert *AssertBase) Nil(i interface{})

Nil asserts that a value is nil

func (*AssertBase) NoError

func (assert *AssertBase) NoError(err error)

NoError asserts that there

func (*AssertBase) NotEmpty

func (assert *AssertBase) NotEmpty(i interface{})

NotEmpty checks for whether a value implements the empty.Value interface and that Empty method does NOT return true.

func (*AssertBase) NotEmptyString

func (assert *AssertBase) NotEmptyString(s string)

NotEmptyString asserts that a string is not empty

func (*AssertBase) NotEqual

func (assert *AssertBase) NotEqual(expected interface{}, actual interface{})

NotEqual asserts that two values are not equal to each other.

func (*AssertBase) NotNil

func (assert *AssertBase) NotNil(i interface{})

NotNil asserts that a value is NOT nil

func (*AssertBase) StartsWith

func (assert *AssertBase) StartsWith(expectedPrefix string, s string)

StartsWith asserts that string begins with another string

func (*AssertBase) StringContains

func (assert *AssertBase) StringContains(needle string, haystack string)

StringContains checks for whether needle is located within haystack.

func (*AssertBase) True

func (assert *AssertBase) True(b bool)

True asserts that a boolean is true

Jump to

Keyboard shortcuts

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