Add test mocking variadic function

pull/175/head
Ernesto Jiménez 2015-06-02 19:59:43 +01:00
parent 93a84c883d
commit d6265bda1a
1 changed files with 23 additions and 0 deletions

View File

@ -44,6 +44,11 @@ func (i *TestExampleImplementation) TheExampleMethodFunc(fn func(string) error)
return args.Error(0)
}
func (i *TestExampleImplementation) TheExampleMethodVariadic(a ...int) error {
args := i.Called(a)
return args.Error(0)
}
type ExampleFuncType func(string) 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) {
// make a test impl object
var mockedService *TestExampleImplementation = new(TestExampleImplementation)