for-GET / katt

KATT (Klarna API Testing Tool) is an HTTP-based API testing tool for Erlang.
https://github.com/for-GET/katt
Apache License 2.0
119 stars 16 forks source link

Add support for asserting [] response body #40

Closed edu-zamora closed 8 years ago

edu-zamora commented 8 years ago

Currently, if you try to assert [] in the response body, katt will crash.

The reason is that katt interprets the [] in the spec file as empty list, but the same thing from the response is interpreted as {array, []}, which fails in tdiff:diff/3.

andreineculau commented 8 years ago

Hi Edu

While the crash shouldn't happen, I agree, from my tests, I think you've missed out on a crucial aspect of the information, and one which could be an accidental error in your blueprint actually:

your blueprint transaction response doesn't have < Content-Type: application/json.

Also, I don't see KATT ever interpreting [] as an empty list but as "[]" i.e. a string made of opening and closing square brackets. Maybe you have been mislead by the error report? ...,{badarg,[{erlang,length,[{array,[]}],[]}...

This is my APIB test with and without a content-type:

--- Test ---

---
---

# Test

GET http://www.mocky.io/v2/56dda46d110000910ad08673
< 200
< Content-Type: application/json{{_}}
[]

GET http://www.mocky.io/v2/56dda46d110000910ad08673
< 200
[]

with the mocked URL being

$ curl -v http://www.mocky.io/v2/56dda46d110000910ad08673
*   Trying 176.34.126.212...
* Connected to www.mocky.io (176.34.126.212) port 80 (#0)
> GET /v2/56dda46d110000910ad08673 HTTP/1.1
> Host: www.mocky.io
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Cowboy
< Connection: close
< Content-Type: application/json; charset=utf-8
< Date: Mon, 07 Mar 2016 16:05:52 GMT
< Via: 1.1 vegur
<
* Closing connection 0
[]

Output:

$ bin/katt hostname=httpbin.org my_name=Joe your_name=Mike -- ./doc/example-httpbin.apib

== PROGRESS REPORT parsing ==
{{2016,3,7},{17,3,24}}

"./doc/example-httpbin.apib"

== PROGRESS REPORT parsed ==
{{2016,3,7},{17,3,24}}

"./doc/example-httpbin.apib"

== PROGRESS REPORT run_transaction ==
{{2016,3,7},{17,3,24}}

<<"# Test\n">>

== PROGRESS REPORT transaction_result ==
{{2016,3,7},{17,3,25}}

{<<"# Test\n">>,
 [{"hostname","httpbin.org"},
  {"my_name","Joe"},
  {"port",80},
  {"protocol","http:"},
  {"request_timeout",20000},
  {"scenario_timeout",120000},
  {"your_name","Mike"}],
 {katt_request,"GET","http://www.mocky.io/v2/56dda46d110000910ad08673",[],
               null},
 {katt_response,200,
                [{"Via","1.1 vegur"},
                 {"Date","Mon, 07 Mar 2016 16:03:24 GMT"},
                 {"Content-Type","application/json; charset=utf-8"},
                 {"Connection","close"},
                 {"Server","Cowboy"}],
                <<"[]">>,
                {array,[]}},
 pass}

== PROGRESS REPORT run_transaction ==
{{2016,3,7},{17,3,25}}

null

{"init terminating in do_boot",{badarg,[{erlang,length,[{array,[]}],[]},{tdiff,diff,3,[{file,"src/tdiff.erl"},{line,176}]},{katt_callbacks,text_diff,2,[{file,"src/katt_callbacks.erl"},{line,210}]},{katt_util,validate_primitive,4,[{file,"src/katt_util.erl"},{line,429}]},{katt_callbacks,validate,4,[{file,"src/katt_callbacks.erl"},{line,186}]},{katt,run_transactions,6,[{file,"src/katt.erl"},{line,203}]},{katt,run_scenario,5,[{file,"src/katt.erl"},{line,155}]},{katt,run,4,[{file,"src/katt.erl"},{line,91}]}]}}
andreineculau commented 8 years ago

Closed via a fix, but reopen if my assumptions about your findings are wrong. Thanks!

edu-zamora commented 8 years ago

Yes, you are correct Andrei, it seems that I was missing < Content-Type: application/json.

Thanks for taking a look at this!

andreineculau commented 8 years ago

the fix was not correct as it introduced another bug, reopening until i have time to investigate properly