Skip to content

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

Open
st0nx wants to merge 1 commit into
rafrombrc:masterfrom
st0nx:use_do_ret
Open

feature: use "Do" return value. Overlap "Return".#7
st0nx wants to merge 1 commit into
rafrombrc:masterfrom
st0nx:use_do_ret

Conversation

@st0nx

@st0nx st0nx commented Jul 27, 2016

Copy link
Copy Markdown

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant