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

Add sorted query feature #50

Merged
merged 1 commit into from
Nov 10, 2018
Merged

Add sorted query feature #50

merged 1 commit into from
Nov 10, 2018

Conversation

konalegi
Copy link
Contributor

Here is the new feature for mocking different mock requests.
Some go libs make HTTP requests with different query items in url.
example for huandu/facebook lib:

// sometimes:
GET http://graph.facebook.com/insights?ids=1,2,3&access_token=123123
// sometimes:
GET http://graph.facebook.com/insights?access_token=123123&ids=1,2,3

The current mock implementation doesn't allow handle this types of requests. My PR allows to pass query items as map and it will always match despite of order.

Usage example:

func TestFetchArticles(t *testing.T) {
	httpmock.Activate()
	httpmock.DeactivateAndReset()
	expecedQuery := map[string]string{
		"a": "1",
		"b": "2"
  }

	httpmock.RegisterResponderWithQuery("GET", "http://example.com/", expecedQuery,
		httpmock.NewStringResponder("hello world", 200))

	// requests to http://example.com?a=1&b=2 and http://example.com?b=2&a=1 will now return 'hello world'
}

We are using my modification in production.

Copy link
Collaborator

@dlebech dlebech left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Before moving on, could you base this on the v1 branch instead of master, as the master branch is no longer supported?

@konalegi konalegi changed the base branch from master to v1 November 2, 2018 07:35
@konalegi
Copy link
Contributor Author

konalegi commented Nov 2, 2018

@dlebech done.

@konalegi
Copy link
Contributor Author

konalegi commented Nov 9, 2018

@dlebech any feedback?

Copy link
Collaborator

@dlebech dlebech left a comment

Choose a reason for hiding this comment

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

Sorry for the wait! Very useful! 💯 🏆

@dlebech dlebech merged commit f085181 into jarcoal:v1 Nov 10, 2018
dlebech pushed a commit that referenced this pull request Nov 17, 2018
This commit addresses an issue that was introduced in commit f085181 (#50)
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