How to mock for same input and different return values in a for loop in golang

I had a similar problem.

The solution was the method Once()

In your mock add an .Once() and repeat the mock with each result you need.

Something like this:

lib.Mock.On("method", arg).Return(test.mockError).Once()
lib.Mock.On("method", arg).Return(nil).Once()

Each mock result will be returned only once.

https://godoc.org/github.com/stretchr/testify/mock#Call.Once

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.