mirror of
https://github.com/stretchr/testify.git
synced 2025-04-27 21:24:09 +00:00
Add test mocking variadic function
This commit is contained in:
parent
93a84c883d
commit
d6265bda1a
@ -44,6 +44,11 @@ func (i *TestExampleImplementation) TheExampleMethodFunc(fn func(string) error)
|
|||||||
return args.Error(0)
|
return args.Error(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *TestExampleImplementation) TheExampleMethodVariadic(a ...int) error {
|
||||||
|
args := i.Called(a)
|
||||||
|
return args.Error(0)
|
||||||
|
}
|
||||||
|
|
||||||
type ExampleFuncType func(string) error
|
type ExampleFuncType func(string) error
|
||||||
|
|
||||||
func (i *TestExampleImplementation) TheExampleMethodFuncType(fn ExampleFuncType) error {
|
func (i *TestExampleImplementation) TheExampleMethodFuncType(fn ExampleFuncType) error {
|
||||||
@ -105,6 +110,24 @@ func Test_Mock_On_WithFuncArg(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_Mock_On_WithVariadicFunc(t *testing.T) {
|
||||||
|
|
||||||
|
// make a test impl object
|
||||||
|
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
|
||||||
|
|
||||||
|
assert.Equal(t, mockedService.On("TheExampleMethodVariadic", []int{1, 2, 3}).Return(nil), &mockedService.Mock)
|
||||||
|
assert.Equal(t, "TheExampleMethodVariadic", mockedService.onMethodName)
|
||||||
|
assert.Equal(t, []int{1, 2, 3}, mockedService.onMethodArguments[0])
|
||||||
|
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
mockedService.TheExampleMethodVariadic(1, 2, 3)
|
||||||
|
})
|
||||||
|
assert.Panics(t, func() {
|
||||||
|
mockedService.TheExampleMethodVariadic(1, 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func Test_Mock_On_WithFuncPanics(t *testing.T) {
|
func Test_Mock_On_WithFuncPanics(t *testing.T) {
|
||||||
// make a test impl object
|
// make a test impl object
|
||||||
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
|
var mockedService *TestExampleImplementation = new(TestExampleImplementation)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user