Closed antonlisovenko closed 3 years ago
Hi @antonlisovenko ,
Since this is a specific case for the empty results, you could use mock.WithRequestMatchHandler
instead:
E.g.
mock.WithRequestMatchHandler(
mock.GetUsersByUsername,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
)
hi @migueleliasweb Yes, this works thanks. I'm still think getting the library panicing on "index out of bounds" if the empty result is returned is not great - but as there's a workaround I'll leave itto you.
Maybe we need to mention somewhere in README that the result cannot be empty or about the workaround with WithRequestMatchHandler
The trick with the WithRequestMatchHandler
option will solve it for now but there might still be a legit use case where you want to return an empty result amongst results with data in them. Like when you have multiple calls to a certain method in the SDK and it might return an empty set depending on a given parameter you passed in one of the calls.
I will have to do some testing to check a few behaviours on the API/SDK and I will come back to you.
@antonlisovenko turns out, empty results were already supported. I've added an example and a test.
This PR adds support for the cases when empty data should be returned (for example if no releases exists - Github returns
http 200
with empty array in this case )