h2non / gock

HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
https://pkg.go.dev/github.com/h2non/gock
MIT License
2.04k stars 106 forks source link

Are you open to adding context expiration/cancellation support? #84

Closed wfscot closed 3 years ago

wfscot commented 3 years ago

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!

h2non commented 3 years ago

Yes, totally open 👍

wfscot commented 3 years ago

Awesome! I just submitted https://github.com/h2non/gock/pull/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!

wfscot commented 3 years ago

Sorry, had to make some further changes to my master branch that screwed up the original PR. Please see https://github.com/h2non/gock/pull/86 instead.