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

Improve MatchBody() by ignoring order of JSON key/values #15

Closed
edwinthinks opened this issue Feb 14, 2017 · 2 comments
Closed

Improve MatchBody() by ignoring order of JSON key/values #15

edwinthinks opened this issue Feb 14, 2017 · 2 comments

Comments

@edwinthinks
Copy link
Contributor

edwinthinks commented Feb 14, 2017

Hello,

I had an issue regarding trying to match JSON payloads with a mocked response even though the keys/values matched exactly. In my search for figuring out why it wasn't working, I noticed that the section in which a check for equality is sensitive to the order by which keys and values are present in the casted string.

My approach to solving this is (at least for JSON) is to convert the byte bodies into a map[string]interface{} and check equality using reflect.DeepEqual(x,y).

I will open a PR shortly with my suggested fixes. I'd like to merge this into master if possible, please let me know if you have any suggestions on how to implement this better.

PR: #16

Thank you 👍

@h2non
Copy link
Owner

h2non commented Feb 14, 2017

Thanks for the PR. Fixes are now shipped as part of the v1.0.4 release.

You can upgrade gock via:

go get -u gopkg.in/h2non/gock.v1

@h2non h2non closed this as completed Feb 14, 2017
@edwinthinks
Copy link
Contributor Author

👍 thanks!

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

No branches or pull requests

2 participants