test

package module
v0.0.0-...-f258696 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: GPL-3.0 Imports: 5 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)
}

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

func (assert *AssertBase) EmptyString(s string)

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)

func (*AssertBase) Failf

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

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{})

func (*AssertBase) NoError

func (assert *AssertBase) NoError(err error)

func (*AssertBase) NotEmptyString

func (assert *AssertBase) NotEmptyString(s string)

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{})

func (*AssertBase) StartsWith

func (assert *AssertBase) StartsWith(expectedPrefix string, s 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)

Jump to

Keyboard shortcuts

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