petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
252 stars 28 forks source link

Add the ability to setup multiple calls for ThenReturn #89

Closed jpopadak closed 5 years ago

jpopadak commented 5 years ago

Right now, ThenReturn validates the values sent into it match the types and number of response values.

However, there is no quick way to setup multiple calls to return different values.

For example, my logic calls RequestToken() this function 3 times, and on the 3rd time I want a different result.

I would expect functionality like this to occur just like Mockito style responses:

    pegomock.When(mockInterf.RequestToken()).ThenReturn(
        auth.Response{}, mockErr,
        auth.Response{}, mockErr,
        mockResponse, nil,
    )

In this scenario, there are 6 values sent to ThenReturn. It would be nice if it could see its a multiple of the values I wanted to send in, and then validate the types (in this case a pair of Response and Error) for each "set of 2" values.

If it doesnt make sense from a user API/DSL side, we could do something like ThenReturnMultiple.

petergtz commented 5 years ago

Hey @jpopadak,

So this one is easy :-). Check out the Stubbing section. Below the example it says:

ThenReturn supports chaining, i.e. ThenReturn(...).ThenReturn(...) etc. The mock will return the values in the same order the chaining was done. The values from the last ThenReturn will be returned indefinitely when the number of call exceeds the ThenReturns.

Hope this helps! If not, let me know how I can improve the description. Thanks, Peter

jpopadak commented 5 years ago

Whoops... I had two other engineers look at this and we didnt see that. 🙄 Sorry about that.