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

Augment RegisterResponderWithQuery function #61

Merged
merged 1 commit into from
Mar 14, 2019
Merged

Conversation

maxatome
Copy link
Collaborator

@maxatome maxatome commented Mar 3, 2019

  • allow to pass several values for one query parameter;
  • fix the case when RegisterResponder register an url with unsorted
    query params: RoundTrip() now checks with url & untouched query
    params before falling back to sorting query params;
  • code simplified to rely on net/url.Values.

Could replace #55 & #57 what do you think of this, @Zanadar and @kardolus?

RegisterResponderWithQueryValues can be renamed if you have a better idea.

transport.go Outdated Show resolved Hide resolved
Copy link

@zmackie zmackie left a comment

Choose a reason for hiding this comment

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

Fist off, cool you're working on this. Maintainers haven't been able to keep up, so I'd recommend a fork and just merge your changes in there.

A few general pieces of feedback: https://github.com/jarcoal/httpmock/pull/61/files#diff-0fecf8d8a1c3b52ef05e62d6a1bf6effR449 (and other methods, I think) should arguably all get updated to take a properly structured net.Values object. The API was wrong to begin with and I would be more agressive about cleaning it up, but release with a bump on the major version.

I also think having RegisterResponderWithQueryValues and RegisterResponderWithQuery is a confusing API. Like, which do I use? I would just make the more aggressive change of compacting them to have the behavior of the RegisterResponderWithQueryValues with the name RegisterResponderWithQuery. If you don't want to do that, RegisterResponderWithQuery should at least call RegisterResponderWithQueryValues under the hood.

@maxatome
Copy link
Collaborator Author

maxatome commented Mar 12, 2019

@Zanadar I agree that having both RegisterResponderWithQueryValues and RegisterResponderWithQuery is confusing. I agree too that RegisterResponderWithQuery should never be released as is, but it is done now. Refering to RegisterResponderWithQueryValues in RegisterResponderWithQuery doc is a step to avoid confusion...

Of course we can bump the major version, but I prefer not. IMO having a new branch will add more confusion than having 2 similar but well documented methods, even if the API is not as clean as it could be in this case.

Note that if you have a better name for RegisterResponderWithQueryValues, do not hesitate to propose it.

By the way, RegisterResponderWithQuery now calls RegisterResponderWithQueryValues as you rightly suggested.

@maxatome
Copy link
Collaborator Author

@Zanadar I just merged RegisterResponderWithQueryValues in RegisterResponderWithQuery. If this design seems correct to you, I will complete unit testing of this stuff.

@maxatome maxatome changed the title Add RegisterResponderWithQueryValues function Augment RegisterResponderWithQuery function Mar 13, 2019
@maxatome
Copy link
Collaborator Author

Unit tests OK.

query type can now be:
- url.Values
- map[string]string
- string, a query string like "a=12&a=13&b=z&c"
  (see net/url.ParseQuery function)

Summary:
- allow to pass several values for one query parameter;
- fix the case when RegisterResponder register an url with unsorted
  query params: RoundTrip() now checks with url & untouched query
  params before falling back to sorting query params;
- code simplified to rely on net/url.Values.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
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.

2 participants