mock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mock provides the small mock API subset used by generated internal test mocks.

Index

Constants

View Source
const Anything = "mock.Anything"

Anything matches any argument.

Variables

This section is empty.

Functions

func AnythingOfType

func AnythingOfType(t string) any

AnythingOfType matches arguments with the provided reflected type string.

func MatchedBy

func MatchedBy(fn any) any

MatchedBy matches arguments accepted by fn.

Types

type Arguments

type Arguments []any

Arguments contains method call arguments or return values.

func (Arguments) Error

func (args Arguments) Error(index int) error

Error returns the argument at index as an error.

func (Arguments) Get

func (args Arguments) Get(index int) any

Get returns the argument at index.

type Call

type Call struct {

	// Method is the expected method name.
	Method string
	// contains filtered or unexported fields
}

Call configures a single expected method call.

func (*Call) Maybe

func (c *Call) Maybe() *Call

Maybe marks the call as optional.

func (*Call) Once

func (c *Call) Once() *Call

Once requires exactly one call.

func (*Call) Return

func (c *Call) Return(values ...any) *Call

Return configures return values for the expected call.

func (*Call) Run

func (c *Call) Run(fn func(args Arguments)) *Call

Run configures a callback that receives actual call arguments.

func (*Call) Times

func (c *Call) Times(n int) *Call

Times requires exactly n calls.

func (*Call) Twice

func (c *Call) Twice() *Call

Twice requires exactly two calls.

type Mock

type Mock struct {
	// contains filtered or unexported fields
}

Mock records expected method calls.

func (*Mock) AssertExpectations

func (m *Mock) AssertExpectations(t TestingT) bool

AssertExpectations verifies that all required calls happened.

func (*Mock) AssertNotCalled

func (m *Mock) AssertNotCalled(t TestingT, method string, args ...any) bool

AssertNotCalled verifies that method was not called with matching arguments.

func (*Mock) Called

func (m *Mock) Called(args ...any) Arguments

Called records the caller method and returns the configured return values.

func (*Mock) MethodCalled

func (m *Mock) MethodCalled(method string, args ...any) Arguments

MethodCalled records method and returns the configured return values.

func (*Mock) On

func (m *Mock) On(method string, args ...any) *Call

On registers an expected method call.

func (*Mock) Test

func (m *Mock) Test(t TestingT)

Test stores the test handle used for expectation failures.

type TestingT

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

TestingT is the testing surface used by generated mock constructors.

Jump to

Keyboard shortcuts

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