h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽

Home Page:https://pkg.go.dev/github.com/h2non/gock

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are you open to adding context expiration/cancellation support?

wfscot opened this issue · comments

Our HTTP proxy application uses contexts pretty extensively to implement timeouts. We also use (and love) gock throughout our unit tests.

I recently added some unit tests around timeouts and noticed in the process that gock does not support context expiration or cancellation. This makes the behavior different than what you'd get using the full HTTP stack. For an example, look here:
https://play.golang.org/p/rKOuNFphpBU (note that you can't run the non-gock version from the Playground)

I looked into the code and I think adding context support is a pretty easy change in response.go. Would you be open to a PR for that?

Thanks!

commented

Yes, totally open 👍

Awesome! I just submitted #85

Note that I did update go.mod as it seemed appropriate. I understand if you'd prefer to ignore those changes although I do expect the build to break for go versions < 1.13.

Also, there was as broken unit test at the start of my fork that remains broken in my fork (TestMatchMock, I didn't touch any of the related code). All the unit tests that I added should pass.

Thanks!

Sorry, had to make some further changes to my master branch that screwed up the original PR. Please see #86 instead.