test

package
v5.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package test contains set of tools used for testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fixture

func Fixture(path string, args ...interface{}) string

Fixture returns the entire contents of the given file as a string. Path be given as Sprintf format and args. Panics on error

func FixtureBytes

func FixtureBytes(path string, args ...interface{}) []byte

FixtureBytes returns the entire contents of the given file as a byte slice. Path can be given as Sprintf format and args. Panics on error.

func MuteLogging

func MuteLogging(t *testing.T)

MuteLogging globally prevents logging output unless TEST_LOGGING env var is not empty

func TODO

func TODO(t *testing.T, message string)

TODO marks a test as being in a "pending" state and logs a message telling the user why. Such tests are expected to fail for the time being and may exist for the sake of unfinished/future features or to document known failure cases that won't be fixed right away. The failure of a pending test is not considered an error and the test will therefore be skipped unless the TEST_TODO environment variable is set to a non-empty value.

Types

type MockCalls

type MockCalls []*mock.Call

MockCalls is a wrapper around []*mock.Call

func (MockCalls) Once

func (mc MockCalls) Once() MockCalls

Once expects calls to be called only one time

func (MockCalls) ReturnErr

func (mc MockCalls) ReturnErr(method string, err error) MockCalls

ReturnErr sets the given error as a last return parameter of the call with the given method

func (MockCalls) Times

func (mc MockCalls) Times(t int) MockCalls

Times sets how many times we expect each call to execute

type TattleT

type TattleT struct{ *testing.T }

TattleT wraps a *testing.T to intercept a Testify mock's call of t.FailNow(). When testing.t.FailNow() is called from any goroutine other than the one on which a test was created, it causes the test to hang. Testify's mocks fail to inform the user which test failed. Use this struct to wrap a *testing.TattleT when you call `mock.Test(TattleT{t})` and the mock's failure message will include the failling test's name. Such failures are usually caused by unexpected method calls on a mock.

NB: You would only need to use this where Testify mocks are used in tests that spawn goroutines, such as those run by the Terraform test driver.

func (TattleT) FailNow

func (t TattleT) FailNow()

FailNow overrides testing.T.FailNow() so when a test mock fails an assertion, we see which test failed

Jump to

Keyboard shortcuts

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