Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from httpmock to gock #31

Merged
merged 3 commits into from May 9, 2022
Merged

Migrate from httpmock to gock #31

merged 3 commits into from May 9, 2022

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented May 5, 2022

This PR migrates our tests from using our homemade httpmock package with the third-party gock package. gock provides all the functionality that httpmock does and more. It also has a nice declarative DSL that is easier to understand, in my opinion. This is an alternative to #29.

cc #28

@samcoe samcoe self-assigned this May 5, 2022
@samcoe samcoe marked this pull request as ready for review May 5, 2022 08:51
@samcoe samcoe requested a review from mislav May 5, 2022 08:51
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great so far!

httpmock.REST("GET", "some/test/path"),
httpmock.StatusStringResponse(200, `{"message": "success"}`),
)
gock.New("https://api.github.com").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of gock.New(), could we use a gock initialization method that doesn't intercept the default http.DefaultTransport, but makes a new transport that we can pass via options to RESTClient()? That way it's more clear what's being initialized, there is no reliance to global state, and we don't have to do t.Cleanup(gock.Off())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could get around this but this check functionality deep in the gock implementation makes it infeasible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see; it looks like the library is designed in a way that it always wants to be used with global intercept. 👍

gh_test.go Outdated Show resolved Hide resolved
gh_test.go Outdated Show resolved Hide resolved
@samcoe samcoe requested a review from mislav May 7, 2022 10:24
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great

@samcoe samcoe merged commit 234a47d into trunk May 9, 2022
@samcoe samcoe deleted the gock branch May 9, 2022 08:20
@samcoe samcoe mentioned this pull request May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants