mock

package
v1.0.42 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 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. You do not have to manually clean up the replacer, as xgo will automatically clear the replacer when current gorotuine exits. However, if you want to clear the replacer earlier, this function returns a clean up function that can be used to clear the replacer.

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