-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement root package using threadsafe
To avoid having and maintaining duplicate code, the root not-threadsafe package is reimplemented using a globl instance of *threadsafe.Gock. I tried to make this as non-breaking of a change as possible, but it could not be done without some breaking changes: * Exported types are just exposing threadsafe types. For example, `type MatchFunc` is changed from `type MatchFunc func(*http.Request, *Request) (bool, error)` to `type MatchFunc = threadsafe.MatchFunc`. The ergonomics of using these types should be unchanged, but it is technically breaking. * Some package-level variables were exposed to allow dynamic configuration, like MatchersHeader. To correctly use the *threadsafe.Gock instance, I had to replace the var with a getter function and add a setter function. For getter use cases, users will just have to append `()` to call the function, but for setter use cases they will need to modify their code a little more (especially if they were doing something like appending to the slice). Other notable things: * I tried to leave as much of the original test suite as possible to prove that this refactor is correct. That means there are some unnecessarily duplicated tests between the root package and `threadsafe`, so there's an opportunity for cleanup. * Some root-level tests relied on unexported symbols which are no longer available to those tests. Some were able to be updated using exported getters, but some were deleted. I believe the deleted tests were not providing additional value because of the above-mentioned duplication. * To correctly maintain the getting and setting of http.DefaultTransport, I added "callback" methods for *threadsafe.Gock: DisableCallback, InterceptCallback, and InterceptingCallback. The root package sets these on the `var g *threadsafe.Gock` variable, and the functions are responsible for reading or writing http.DefaultTransport. Implementing this logic in the original functions (e.g. `gock.Disable`) proved too odd since the some of the functions call others. We would have to retain some duplicate implementation logic to run the logic in the right place, so the callback methods felt like the cleanest workaround.
- Loading branch information
Showing
17 changed files
with
189 additions
and
1,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.