Skip to content

Commit

Permalink
Add test cases mocking methods with Func arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ernesto-jimenez committed May 6, 2015
1 parent 73a8112 commit 8bfd855
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ func (i *TestExampleImplementation) TheExampleMethod3(et *ExampleType) error {
return args.Error(0)
}

func (i *TestExampleImplementation) TheExampleMethodFunc(fn func(string) error) error {
args := i.Called(fn)
return args.Error(0)
}

type ExampleFuncType func(string) error

func (i *TestExampleImplementation) TheExampleMethodFuncType(fn ExampleFuncType) error {
args := i.Called(fn)
return args.Error(0)
}

/*
Mock
*/
Expand Down Expand Up @@ -79,6 +91,34 @@ func Test_Mock_On_WithArgs(t *testing.T) {

}

func Test_Mock_On_WithFuncArg(t *testing.T) {

// make a test impl object
var mockedService *TestExampleImplementation = new(TestExampleImplementation)

assert.Equal(t, mockedService.On("TheExampleMethodFunc", AnythingOfType("func(string) error")).Return(nil), &mockedService.Mock)
assert.Equal(t, "TheExampleMethodFunc", mockedService.onMethodName)
assert.Equal(t, AnythingOfType("func(string) error"), mockedService.onMethodArguments[0])

fn := func(string) error { return nil }
mockedService.TheExampleMethodFunc(fn)

}

func Test_Mock_On_WithFuncTypeArg(t *testing.T) {

// make a test impl object
var mockedService *TestExampleImplementation = new(TestExampleImplementation)

assert.Equal(t, mockedService.On("TheExampleMethodFuncType", AnythingOfType("mock.ExampleFuncType")).Return(nil), &mockedService.Mock)
assert.Equal(t, "TheExampleMethodFuncType", mockedService.onMethodName)
assert.Equal(t, AnythingOfType("mock.ExampleFuncType"), mockedService.onMethodArguments[0])

fn := func(string) error { return nil }
mockedService.TheExampleMethodFuncType(fn)

}

func Test_Mock_Return(t *testing.T) {

// make a test impl object
Expand Down

0 comments on commit 8bfd855

Please sign in to comment.