gomockhelper

package module
v0.0.0-...-cff279b Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: MIT Imports: 2 Imported by: 0

README

gomockhelper

ci PkgGoDev codecov Go Report Card

helpers for gomock

Example

Expect all methods of the target mock with gomock. test code

License

MIT

Author

Mitsuo Heijo (@johejo)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectAll

func ExpectAll(ctrl *gomock.Controller, mock interface{}, args []interface{}, callFunc func(call *gomock.Call))

ExpectAll expects all methods of target mock with gomock. Passing nil in args will use gomock.Any() for all arguments. If you want to use Do or DoAndReturn of gomock.Call, you can use it by passing a function to callFunc. Example: func(call *gomock.Call) { call.Return("return", 5050)}

Example
t := new(testing.T) // *testing.T

ctrl := gomock.NewController(t)
defer ctrl.Finish()

var mockDoer1 Doer1 = mock.NewMockDoer1(ctrl)
gomockhelper.ExpectAll(ctrl, mockDoer1, []interface{}{}, nil)

mockDoer1.Do1()
mockDoer1.Do2()
mockDoer1.Do3()

var mockDoer2 Doer2 = mock.NewMockDoer2(ctrl)
gomockhelper.ExpectAll(ctrl, mockDoer2, []interface{}{1234, "arg"}, func(call *gomock.Call) {
	call.Return("foo", 5050)
})

fmt.Println(mockDoer2.DoWithReturns1(1234, "arg"))
fmt.Println(mockDoer2.DoWithReturns2(1234, "arg"))
Output:

foo 5050
foo 5050

Types

This section is empty.

Directories

Path Synopsis
Package mock_gomockhelper_test is a generated GoMock package.
Package mock_gomockhelper_test is a generated GoMock package.

Jump to

Keyboard shortcuts

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