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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)