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

Cleanup httpmock #29

Closed
wants to merge 3 commits into from
Closed

Cleanup httpmock #29

wants to merge 3 commits into from

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented May 2, 2022

This PR gets the package formerly known as httpmock into a state that it can be made public and moved out of the internal folder.

Some major changes:

  • Change package name to transportmock
  • Require names for stubs
  • Removed extraneous responders
  • Allow responders to handle strings and interface input

I left comments for open questions inline.

cc #28


type Matcher func(req *http.Request) bool

func REST(method, p string) Matcher {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do we think about the naming scheme here? Should we prefix/postfix Match/Matcher to this and the GQL function?

Comment on lines +13 to +14
stubs []*stub
requests []*http.Request
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 purposefully un-exported these and added a Requests() accessor function. It felt smart to move this direction incase we want to change the underlying implementation.

}
if stub != nil {
r.mu.Unlock()
dr, _ := httputil.DumpRequestOut(req, true)
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 think using DumpRequestOut leads to nicer looking error messages.


type Responder func(req *http.Request) (*http.Response, error)

func HTTPResponse(status int, header *map[string][]string, body interface{}, cb func(*http.Request)) Responder {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do we think about the naming scheme for Responders? Should we prefix/postfix them with Response/Responder?

}
}

func RESTResponse(body interface{}, cb func(map[string]interface{})) Responder {
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 think having HTTPResponse and RESTResponse to be a bit confusing. Open to better naming here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any less confusing if you call RESTResponse a JSONResponse? Afterall, it's just the response itself which happens to be JSON. Perhaps HTTPResponse could be RAWResponse and uses for non-JSON payloads - perhaps with a content-type? More focus on the payload than how it was retrieved.

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

samcoe commented May 9, 2022

Closing as we decided against exporting httpmock in favor of migrating to gock in #31.

@samcoe samcoe closed this 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