assertions

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqualEvents

func AssertEqualEvents(t TB, expected, actual sdk.Events, msgAndArgs ...interface{}) bool

AssertEqualEvents asserts that the expected events equal the actual events.

Returns success (true = they're equal, false = they're different).

func AssertEqualEventsf

func AssertEqualEventsf(t TB, expected, actual sdk.Events, msg string, args ...interface{}) bool

AssertEqualEventsf asserts that the expected events equal the actual events.

Returns success (true = they're equal, false = they're different).

func AssertErrorContents

func AssertErrorContents(t TB, theError error, contains []string, msgAndArgs ...interface{}) bool

AssertErrorContents asserts that the provided error is as expected. If contains is empty, it asserts there is no error. Otherwise, it asserts that the error contains each of the entries in the contains slice.

Returns true if it's all good, false if one or more assertions failed.

func AssertErrorContentsf

func AssertErrorContentsf(t TB, theError error, contains []string, msg string, args ...interface{}) bool

AssertErrorContentsf asserts that the provided error is as expected. If contains is empty, it asserts there is no error. Otherwise, it asserts that the error contains each of the entries in the contains slice.

Returns true if it's all good, false if one or more assertions failed.

func AssertErrorValue

func AssertErrorValue(t TB, theError error, expected string, msgAndArgs ...interface{}) bool

AssertErrorValue asserts that, if an error is expected, theError equals the expected, otherwise asserts that there wasn't an error.

Returns true if it's all good, false if the assertion failed.

func AssertErrorValuef

func AssertErrorValuef(t TB, theError error, expected string, msg string, args ...interface{}) bool

AssertErrorValuef asserts that, if an error is expected, theError equals the expected, otherwise asserts that there wasn't an error.

Returns true if it's all good, false if the assertion failed.

func AssertEventsContains added in v1.18.0

func AssertEventsContains(t TB, expected, actual sdk.Events, msgAndArgs ...interface{}) bool

AssertEventsContains asserts that each of the provided expected events is contained in the provided actual events.

Returns success (true = they're all there, false = one or more is missing).

func AssertEventsContainsf added in v1.18.0

func AssertEventsContainsf(t TB, expected, actual sdk.Events, msg string, args ...interface{}) bool

AssertEventsContainsf asserts that each of the provided expected events is contained in the provided actual events.

Returns success (true = they're all there, false = one or more is missing).

func AssertNotPanicsNoError

func AssertNotPanicsNoError(t TB, f ErrorTestFunc, msgAndArgs ...interface{}) bool

AssertNotPanicsNoError asserts that the code inside the provided function does not panic and that it does not return an error.

Returns true if it neither panics nor errors, returns false otherwise.

func AssertNotPanicsNoErrorf

func AssertNotPanicsNoErrorf(t TB, f ErrorTestFunc, msg string, args ...interface{}) bool

AssertNotPanicsNoErrorf asserts that the code inside the provided function does not panic and that it does not return an error.

Returns true if it neither panics nor errors, returns false otherwise.

func AssertPanicContents

func AssertPanicContents(t TB, f PanicTestFunc, contains []string, msgAndArgs ...interface{}) bool

AssertPanicContents asserts that, if contains is empty, the provided func does not panic Otherwise, asserts that the func panics and that its panic message contains each of the provided strings.

Returns true if it's all good, false if an assertion fails.

func AssertPanicContentsf

func AssertPanicContentsf(t TB, f PanicTestFunc, contains []string, msg string, args ...interface{}) bool

AssertPanicContentsf asserts that, if contains is empty, the provided func does not panic Otherwise, asserts that the func panics and that its panic message contains each of the provided strings.

Returns true if it's all good, false if an assertion fails.

func AssertPanicEquals

func AssertPanicEquals(t TB, f PanicTestFunc, expected string, msgAndArgs ...interface{}) bool

AssertPanicEquals asserts that, if a panic is expected, the provided func panics with the expected output string. And if a panic is not expected, asserts that the provided func does not panic.

Returns true if it's all good, false if an assertion fails.

This can be preferred over PanicsWithError or PanicsWithValue because it doesn't require the panic to be a specific type.

func AssertPanicEqualsf

func AssertPanicEqualsf(t TB, f PanicTestFunc, expected string, msg string, args ...interface{}) bool

AssertPanicEqualsf asserts that, if a panic is expected, the provided func panics with the expected output string. And if a panic is not expected, asserts that the provided func does not panic.

Returns true if it's all good, false if an assertion fails.

This can be preferred over PanicsWithErrorf or PanicsWithValuef because it doesn't require the panic to be a specific type.

func AttrsToStrings

func AttrsToStrings(attrs []abci.EventAttribute) []string

AttrsToStrings creates and returns a string for each attribute.

func EventToString added in v1.18.0

func EventToString(event sdk.Event) string

EventToString converts a single event to a one-line string.

func EventToStrings

func EventToStrings(event sdk.Event) []string

EventToStrings converts a single event to strings, one string per attribute.

func EventsToStrings

func EventsToStrings(events sdk.Events) []string

EventsToStrings converts events to strings representing the events, one line per attribute.

func PrependToEach

func PrependToEach(prefix string, lines []string) []string

PrependToEach prepends the provided prefix to each of the provide lines.

func RequireEqualEvents

func RequireEqualEvents(t TB, expected, actual sdk.Events, msgAndArgs ...interface{})

RequireEqualEvents asserts that the expected events equal the actual events.

Returns if they're equal, halts tests if not.

func RequireEqualEventsf

func RequireEqualEventsf(t TB, expected, actual sdk.Events, msg string, args ...interface{})

RequireEqualEventsf asserts that the expected events equal the actual events.

Returns if they're equal, halts tests if not.

func RequireErrorContents

func RequireErrorContents(t TB, theError error, contains []string, msgAndArgs ...interface{})

RequireErrorContents asserts that the provided error is as expected. If contains is empty, it asserts there is no error. Otherwise, it asserts that the error contains each of the entries in the contains slice.

Returns if it's all good, halts the test if one or more assertions failed.

func RequireErrorContentsf

func RequireErrorContentsf(t TB, theError error, contains []string, msg string, args ...interface{})

RequireErrorContentsf asserts that the provided error is as expected. If contains is empty, it asserts there is no error. Otherwise, it asserts that the error contains each of the entries in the contains slice.

Returns if it's all good, halts the test if one or more assertions failed.

func RequireErrorValue

func RequireErrorValue(t TB, theError error, expected string, msgAndArgs ...interface{})

RequireErrorValue asserts that, if an error is expected, theError equals the expected, otherwise asserts that there wasn't an error.

Returns if it's all good, halts the test if the assertion failed.

func RequireErrorValuef

func RequireErrorValuef(t TB, theError error, expected string, msg string, args ...interface{})

RequireErrorValuef asserts that, if an error is expected, theError equals the expected, otherwise asserts that there wasn't an error.

Returns if it's all good, halts the test if the assertion failed.

func RequireEventsContains added in v1.18.0

func RequireEventsContains(t TB, expected, actual sdk.Events, msgAndArgs ...interface{})

RequireEventsContains asserts that each of the provided expected events is contained in the provided actual events.

Returns if they're all there, halts tests if not.

func RequireEventsContainsf added in v1.18.0

func RequireEventsContainsf(t TB, expected, actual sdk.Events, msg string, args ...interface{})

RequireEventsContainsf asserts that each of the provided expected events is contained in the provided actual events.

Returns if they're all there, halts tests if not.

func RequireNotPanicsNoError

func RequireNotPanicsNoError(t TB, f ErrorTestFunc, msgAndArgs ...interface{})

RequireNotPanicsNoError asserts that the code inside the provided function does not panic and that it does not return an error.

Returns if it neither panics nor errors, otherwise it halts the test.

func RequireNotPanicsNoErrorf

func RequireNotPanicsNoErrorf(t TB, f ErrorTestFunc, msg string, args ...interface{})

RequireNotPanicsNoErrorf asserts that the code inside the provided function does not panic and that it does not return an error.

Returns if it neither panics nor errors, otherwise it halts the test.

func RequirePanicContents

func RequirePanicContents(t TB, f PanicTestFunc, contains []string, msgAndArgs ...interface{})

RequirePanicContents asserts that, if contains is empty, the provided func does not panic Otherwise, asserts that the func panics and that its panic message contains each of the provided strings.

Returns if it's all good, halts the test if the assertion failed.

func RequirePanicContentsf

func RequirePanicContentsf(t TB, f PanicTestFunc, contains []string, msg string, args ...interface{})

RequirePanicContentsf asserts that, if contains is empty, the provided func does not panic Otherwise, asserts that the func panics and that its panic message contains each of the provided strings.

Returns if it's all good, halts the test if the assertion failed.

func RequirePanicEquals

func RequirePanicEquals(t TB, f PanicTestFunc, expected string, msgAndArgs ...interface{})

RequirePanicEquals asserts that, if a panic is expected, the provided func panics with the expected output string. And if a panic is not expected, asserts that the provided func does not panic.

Returns if it's all good, halts the test if the assertion failed.

This can be preferred over PanicsWithError or PanicsWithValue because it doesn't require the panic to be a specific type.

func RequirePanicEqualsf

func RequirePanicEqualsf(t TB, f PanicTestFunc, expected string, msg string, args ...interface{})

RequirePanicEqualsf asserts that, if a panic is expected, the provided func panics with the expected output string. And if a panic is not expected, asserts that the provided func does not panic.

Returns if it's all good, halts the test if the assertion failed.

This can be preferred over PanicsWithErrorf or PanicsWithValuef because it doesn't require the panic to be a specific type.

Types

type ErrorTestFunc

type ErrorTestFunc func() error

ErrorTestFunc is a type declaration for a function that will be tested for an error.

type PanicTestFunc

type PanicTestFunc func()

PanicTestFunc is a type declaration for a function that will be tested for panic.

type TB

type TB interface {
	Helper()
	Errorf(format string, args ...any)
	Logf(format string, args ...any)
	FailNow()
}

TB is a paired down version of the testing.TB interface with just the stuff needed in here.

I'm kind of annoyed that I needed to do this, but it's the only way I could figure out to have unit tests on these assertions that would check failure conditions, but not fail the parent test.

Jump to

Keyboard shortcuts

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