moxie

command module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MIT Imports: 11 Imported by: 0

README

lesiw.io/moxie: Generate mocks with proxy functions

Go has a convenient feature called embedding. Method calls are transparently passed through to embedded types.

moxie generates proxy methods that are only added during go test.

Usage

Add this line to your code, where T is the type you want to instrument, and E is the embedded type whose functions you want to intercept.

//go:generate go run lesiw.io/moxie@latest T
type T struct {
    E
}

Then run go generate.

Functions

moxie makes the following functions available at test time.

Mock
(*T)._Func_Stub()           -> when called, return zero values.
(*T)._Func_Return(...)      -> when called, return these values.
(*T)._Func_Do(func() {...}) -> when called, run this instead.
                               calling this with nil will un-mock the function.

Mocks queue. For example, mocking with (*T)._Func_Return twice will return the first set of values the next time the function is called, then return the second set of values in subsequent calls.

Inspect
(*T)._Func_Calls() []_T_Func_Call -> return calls to Func.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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