gomock
gomock copied to clipboard
feature: use "Do" return value. Overlap "Return".
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>