openresty / test-nginx

Data-driven test scaffold for Nginx C module and OpenResty Lua library development
http://search.cpan.org/dist/Test-Nginx
438 stars 105 forks source link

json comparison on --- response_body #159

Closed skelzer closed 1 year ago

skelzer commented 1 year ago

Hello!,

First of all, sorry if this is a dumb question, but I have never used nginx or Perl before, so I'm a bit at a loss.

I am trying to validate an endpoint that should serve a JSON as a response. Since JSONs are by definition unsorted, how should I go about validating this response? Is this even possible in this framework?

Thanks :)

zhuizhuhaomeng commented 1 year ago

I think we can extend the test-nginx framework.

add a new session which will sort the json before compare the body --- response_body_json:

skelzer commented 1 year ago

Awesome, that worked great :)

frankgreco commented 8 months ago

This was a life saver. Could we add this to this guide: https://openresty.gitbooks.io/programming-openresty/content/testing/test-file-layout.html

zhuizhuhaomeng commented 8 months ago

@frankgreco would you please create a PR for your proposal?

https://github.com/openresty/programming-openresty/

frankgreco commented 8 months ago

@zhuizhuhaomeng It seems the version installed when doing cpan install Test::Nginx is 0.30 which does not contain this fix. I had to build from source for it to work. Would you be able to publish a new version of this module?