boilerplate

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RepeatForever, can be used with:
	//	OnMock().Repeat(mocks.RepeatForever).
	RepeatForever int = -1
)

Functions

This section is empty.

Types

type Call

type Call[T any] struct {
	// contains filtered or unexported fields
}

func (*Call[T]) Draw

func (c *Call[T]) Draw() (f T, empty bool)

Draw is a card Draw design, in which each call determines when to get removed from the deck. if repeat == 0, the call gets removed from deck. setting repeat = -1 will skip this condition, allowing it to repeat indefinitely through the group.

func (*Call[T]) Maybe

func (c *Call[T]) Maybe()

func (*Call[T]) Repeat

func (c *Call[T]) Repeat(times int)

type Config

type Config interface {
	// Repeat sets how many times the function group should be called, note that if more than 1 function is given,
	// all the functions should repeat n times.
	// Repeat is 1 by default, meaning that functions can only be called 1 time.
	// Set Repeat(-1) to allow the group to repeat indefinitely.
	Repeat(times int)
	// Maybe sets the group as not required for AssertExpectations,
	// meaning that the function group will not fail the test if not called.
	Maybe()
}

Config represents the configuration for all the functions passed to the On... function.

type Mock

type Mock[T any] struct {
	// contains filtered or unexported fields
}

func NewMock

func NewMock[T any](t *testing.T) Mock[T]

func (*Mock[T]) Append

func (c *Mock[T]) Append(f ...T) Config

Append creates a new card for the group of functions given, returning Config. With Config you can configure the group expectations.

func (*Mock[T]) AssertExpectations

func (c *Mock[T]) AssertExpectations(t *testing.T) bool

AssertExpectations asserts that all expected function calls have been called. Returns true if all expectations were met, otherwise returns false.

func (*Mock[T]) Call

func (c *Mock[T]) Call() (*T, bool)

Call returns a func of type T and a bool from the deck. It either returns (func, true) or (nil, false).

Jump to

Keyboard shortcuts

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