Documentation
¶
Index ¶
- func GetGoroutineId() int64
- func GetMethod(instance interface{}, methodName string) interface{}
- func GetNestedMethod(instance interface{}, methodName string) interface{}
- func GetPrivateMethod(instance interface{}, methodName string) interface{}
- func OptGeneric(o *option)
- func OptUnsafe(o *option)
- func PatchConvey(items ...interface{})
- func Sequence(value ...interface{}) sequenceOpt
- type FilterGoroutineType
- type MockBuilder
- func (builder *MockBuilder) Build() *Mocker
- func (builder *MockBuilder) ExcludeCurrentGoRoutine() *MockBuilder
- func (builder *MockBuilder) FilterGoRoutine(filter FilterGoroutineType, gId int64) *MockBuilder
- func (builder *MockBuilder) IncludeCurrentGoRoutine() *MockBuilder
- func (builder *MockBuilder) Origin(funcPtr interface{}) *MockBuilder
- func (builder *MockBuilder) Return(results ...interface{}) *MockBuilder
- func (builder *MockBuilder) To(hook interface{}) *MockBuilder
- func (builder *MockBuilder) When(when interface{}) *MockBuilder
- type Mocker
- func (mocker *Mocker) ExcludeCurrentGoRoutine() *Mocker
- func (mocker *Mocker) FilterGoRoutine(filter FilterGoroutineType, gId int64) *Mocker
- func (mocker *Mocker) IncludeCurrentGoRoutine() *Mocker
- func (mocker *Mocker) MockTimes() int
- func (mocker *Mocker) Origin(funcPtr interface{}) *Mocker
- func (mocker *Mocker) Patch() *Mocker
- func (mocker *Mocker) Release() *MockBuilder
- func (mocker *Mocker) Return(results ...interface{}) *Mocker
- func (mocker *Mocker) Times() int
- func (mocker *Mocker) To(to interface{}) *Mocker
- func (mocker *Mocker) UnPatch() *Mocker
- func (mocker *Mocker) When(when interface{}) *Mocker
- type MockerVar
- type MockeyPrivate
- type Private
- type SequenceOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMethod ¶
func GetMethod(instance interface{}, methodName string) interface{}
GetMethod resolve a certain public method from an instance.
func GetNestedMethod ¶
func GetNestedMethod(instance interface{}, methodName string) interface{}
GetNestedMethod resolves a certain public method in anonymous structs, it will look for the specific method in every anonymous struct field recursively. Deprecated, use GetMethod instead.
func GetPrivateMethod ¶
func GetPrivateMethod(instance interface{}, methodName string) interface{}
GetPrivateMethod ... Deprecated, use GetMethod instead.
func OptGeneric ¶ added in v1.2.5
func OptGeneric(o *option)
func PatchConvey ¶
func PatchConvey(items ...interface{})
Types ¶
type FilterGoroutineType ¶
type FilterGoroutineType int64
const ( Disable FilterGoroutineType = 0 Include FilterGoroutineType = 1 Exclude FilterGoroutineType = 2 )
type MockBuilder ¶
type MockBuilder struct {
// contains filtered or unexported fields
}
func Mock ¶
func Mock(target interface{}, opt ...optionFn) *MockBuilder
func MockGeneric ¶ added in v1.2.5
func MockGeneric(target interface{}) *MockBuilder
func MockUnsafe ¶ added in v1.1.0
func MockUnsafe(target interface{}) *MockBuilder
MockUnsafe has the full ability of the Mock function and removes some security restrictions. This is an alternative when the Mock function fails. It may cause some unknown problems, so we recommend using Mock under normal conditions.
func (*MockBuilder) Build ¶
func (builder *MockBuilder) Build() *Mocker
func (*MockBuilder) ExcludeCurrentGoRoutine ¶
func (builder *MockBuilder) ExcludeCurrentGoRoutine() *MockBuilder
func (*MockBuilder) FilterGoRoutine ¶
func (builder *MockBuilder) FilterGoRoutine(filter FilterGoroutineType, gId int64) *MockBuilder
func (*MockBuilder) IncludeCurrentGoRoutine ¶
func (builder *MockBuilder) IncludeCurrentGoRoutine() *MockBuilder
func (*MockBuilder) Origin ¶
func (builder *MockBuilder) Origin(funcPtr interface{}) *MockBuilder
func (*MockBuilder) Return ¶
func (builder *MockBuilder) Return(results ...interface{}) *MockBuilder
func (*MockBuilder) To ¶
func (builder *MockBuilder) To(hook interface{}) *MockBuilder
To declares the hook function that's called to replace the target function.
The hook function must have the same signature as the target function.
The following example would make Fun always return true
func Fun(input string) bool { return input == "fun" } Mock(Fun).To(func(_ string) bool {return true}).Build()
Note that if the target function is a struct method, you may optionally include the receiver as the first argument of the hook function. For example,
type Foo struct { Name string } func (f *Foo) Bar(other string) bool { return other == f.Name } Mock((*Foo).Bar).To(func(f *Foo, other string) bool {return true}).Build()
func (*MockBuilder) When ¶
func (builder *MockBuilder) When(when interface{}) *MockBuilder
When declares the condition hook that's called to determine whether the mock should be executed.
The condition hook function must have the same parameters as the target function.
The following example would execute the mock when input int is negative
func Fun(input int) string { return strconv.Itoa(input) } Mock(Fun).When(func(input int) bool { return input < 0 }).Return("0").Build()
Note that if the target function is a struct method, you may optionally include the receiver as the first argument of the condition hook function. For example,
type Foo struct { Age int } func (f *Foo) GetAge(younger int) string { return strconv.Itoa(f.Age - younger) } Mock((*Foo).GetAge).When(func(f *Foo, younger int) bool { return younger < 0 }).Return("0").Build()
type Mocker ¶
type Mocker struct {
// contains filtered or unexported fields
}
func (*Mocker) ExcludeCurrentGoRoutine ¶
func (*Mocker) FilterGoRoutine ¶
func (mocker *Mocker) FilterGoRoutine(filter FilterGoroutineType, gId int64) *Mocker
func (*Mocker) IncludeCurrentGoRoutine ¶
func (*Mocker) Release ¶ added in v1.2.3
func (mocker *Mocker) Release() *MockBuilder
type MockeyPrivate ¶ added in v1.2.4
type MockeyPrivate struct{}
type Private ¶ added in v1.2.4
type Private interface {
// contains filtered or unexported methods
}
type SequenceOpt ¶ added in v1.2.4
type SequenceOpt interface { // make sure it is mockey private interface Private // GetNext is used by mockey, don't use it if you don't know what it does GetNext() []interface{} }