mock

package
v1.0.35 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCallOld = errors.New("mock: call old")

a marker to indicate the original function should be called

Functions

func CallOld

func CallOld()

func Mock

func Mock(fn interface{}, interceptor Interceptor) func()

Mock setup mock on given function `fn`. `fn` can be a function or a method, if `fn` is a method, only the bound instance will be mocked, other instances are not affected. The returned function can be used to cancel the passed interceptor.

func MockByName

func MockByName(pkgPath string, funcName string, interceptor Interceptor) func()

func MockMethodByName

func MockMethodByName(instance interface{}, method string, interceptor Interceptor) func()

Can instance be nil?

func Patch

func Patch(fn interface{}, replacer interface{}) func()

Patch replaces `fn` with `replacer` in current goroutine, it returns a cleanup function to remove `replacer`. the `replacer` will be automatically cleared when current gorotuine exits if the returned cleanup function is not called.

func PatchByName

func PatchByName(pkgPath string, funcName string, replacer interface{}) func()

func PatchMethodByName

func PatchMethodByName(instance interface{}, method string, replacer interface{}) func()

Types

type Interceptor

type Interceptor func(ctx context.Context, fn *core.FuncInfo, args core.Object, results core.Object) error

Jump to

Keyboard shortcuts

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