mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mock holds what the gRPC and HTTP mock servers have in common: how failures are reported, and how many times an expectation may and must be matched. The servers themselves live beside the packages they stand in for, in go/grpc/mock_server and go/http/mock_server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cardinality

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

Cardinality tracks how many times an expectation may and must be matched. The zero value is not usable; construct it with NewCardinality, which matches an unlimited number of times and requires at least one match.

It is embedded in each server's expectation type, which re-declares Times and AnyTimes to return itself so that options stay chainable.

func NewCardinality

func NewCardinality() Cardinality

NewCardinality returns a cardinality requiring at least one match, with no upper bound.

func (*Cardinality) AnyTimes

func (c *Cardinality) AnyTimes()

AnyTimes lets the expectation match any number of times, including none.

func (*Cardinality) Exhausted

func (c *Cardinality) Exhausted() bool

Exhausted reports whether the expectation has taken every match it was declared for, and so should be skipped in favour of later expectations on the same endpoint.

func (*Cardinality) Record

func (c *Cardinality) Record()

Record counts a match.

func (*Cardinality) Times

func (c *Cardinality) Times(count int)

Times requires the expectation to be matched exactly count times.

func (*Cardinality) Verify

func (c *Cardinality) Verify() string

Verify returns the reason the expectation was not satisfied, or an empty string.

type TestingT

type TestingT interface {
	Errorf(format string, arguments ...any)
	Helper()
}

TestingT is the subset of *testing.T the mocks report failures through. It is an interface rather than the concrete type so that a mock's own tests can assert on the failures it reports instead of being failed by them.

Jump to

Keyboard shortcuts

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