mocktesting

package
v6.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package mocktesting contains a mock instance of *testing.T which is useful for testing interchaintest's interactions with Go tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T struct {
	HelperCalled bool

	Logs   []string
	Errors []string
	Skips  []string

	// ParallelDelay sets how long to sleep on a call to t.Parallel,
	// for tests that need to simulate t.Parallel blocking.
	ParallelDelay time.Duration
	// contains filtered or unexported fields
}

T satisfies a subset of testing.TB useful for tests around how interchaintest interacts with instances of testing.T.

The methods that are unique to T are RunCleanups and Simulate

func NewT

func NewT(name string) *T

NewT returns a new T with the given name.

func (*T) Cleanup

func (t *T) Cleanup(f func())

Cleanup adds f to the list of cleanup functions to invoke. To actually invoke the functions, use t.RunCleanups.

func (*T) Errorf

func (t *T) Errorf(format string, args ...any)

Errorf appends the formatted error message to t.Errors.

func (*T) Fail

func (t *T) Fail()

Fail marks t as failed, without any control flow interaction.

func (*T) FailNow

func (t *T) FailNow()

FailNow marks T as failed and stops execution. FailNow panics if called outside the context of RunTest.

func (*T) Failed

func (t *T) Failed() bool

Failed reports whether t.Errorf was ever called.

func (*T) Helper

func (t *T) Helper()

Helper sets the t.HelperCalled field to true.

func (*T) Logf

func (t *T) Logf(format string, args ...any)

Logf appends the formatted message to t.Logs.

func (*T) Name

func (t *T) Name() string

Name returns the name provided to NewT.

func (*T) Parallel

func (t *T) Parallel()

Parallel blocks for the configured t.ParallelDelay and then returns.

func (*T) RunCleanups

func (t *T) RunCleanups()

RunCleanups runs all the functions passed to t.Cleanup, in reverse order just like the real testing.T.

func (*T) Simulate

func (t *T) Simulate(fn func())

Simulate executes the given function in its own goroutine, which is necessary for exercising methods that affect control flow, such as t.Skip or t.FailNow.

Simulate also runs t.RunCleanups after fn's execution finishes.

func (*T) Skip

func (t *T) Skip(args ...any)

Skip appends fmt.Sprint(args...) to t.Skips. Skip panics if called outside the context of RunTest.

func (*T) Skipped

func (t *T) Skipped() bool

Skipped reports whether t.Skip was ever called.

Jump to

Keyboard shortcuts

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