gomock icon indicating copy to clipboard operation
gomock copied to clipboard

feature: use "Do" return value. Overlap "Return".

Open st0nx opened this issue 8 years ago • 0 comments

Sometimes need to return a different value for different input arguments. I think it would be more convenient.

Example:

func TestRead(t *testing.T) {
    mockCtrl := gomock.NewController(t)
    defer mockCtrl.Finish()
    mockObj := mock_io.NewMockReadWriteCloser(mockCtrl)
    do := func(d []byte) (int, error) {
        return len(d), nil
    }
    mockObj.EXPECT().Read(gomock.Any()).AnyTimes().Do(do)
    fmt.Println(mockObj.Read([]byte{0x1}))
    fmt.Println(mockObj.Read([]byte{0x1, 0x1, 0x1}))
}
1 <nil>
3 <nil>

st0nx avatar Jul 27 '16 10:07 st0nx