3

Dredd tests of APIary calls returning an image / PNG fail. Is it possible to check not the content of the returned image but just that there is an image not null as response?

Here is the output of my test:

 [31mfail [39m: GET /imp-endpoint/api/V1/Resources?left_lower_lat=52.482780222078205&left_lower_lng=13.3154296875&right_upper_lng=13.359375&right_upper_lat=52.50953477032729&width=250&heigth=250 duration: 1176ms
 [31mfail [39m: body: Real and expected data does not match.

 [32mrequest [39m: 
body: 

headers: 
    accept: image/png
    User-Agent: Dredd/0.3.7 (Linux 3.5.0-52-generic; ia32)
    Authorization: Basic ZG1wOmRtcEAxMjM0

uri: /imp-endpoint/api/V1/Resources?left_lower_lat=52.482780222078205&left_lower_lng=13.3154296875&right_upper_lng=13.359375&right_upper_lat=52.50953477032729&width=250&heigth=250
method: GET


 [31mexpected [39m: 
headers: 
    content-type: image/png

body: 
�PNG

statusCode: 200


 [31mactual [39m: 
statusCode: 200
headers: 
    x-powered-by: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
    server: GlassFish Server Open Source Edition 3.1.2.2
    access-control-allow-origin: *
    access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
    content-type: image/png
    content-length: 26572
    date: Tue, 15 Jul 2014 09:00:26 GMT

body: 
�PNG


IHDR    � ?1g�IDATx^��

2 Answers2

0

This is a known limitation. As Adam states on linked page, binary blobs are not supported in the API Blueprint format at this moment and can't be used for testing with Dredd.

We (Apiary) plan to actually support binary files properly in the blueprint, but until it happens, it's true that we should provide a way for the API to pass the validations.

As a hairy workaround you could specify empty HTTP body and proper Content-Length header so testing of body gets omitted.

Honza Javorek
  • 8,566
  • 8
  • 47
  • 66
  • This behavior seems to have changed in Dredd since this was written. Specifying an empty body + proper content-length header still results in a failure in Dredd. The error message in the Apiary testing site shows as "Real and expected data does not match." on the "Body". – Jay Klehr Feb 23 '16 at 01:18
0

As a workaround, you can use:

hooks.beforeValidation('User > Avatar > Get Mine', function (transaction) {
  transaction.expected.headers['content-length'] = 9999;
  transaction.real.body = '';
});

Or even, set content length header on the blueprint, like this:

+ Response 200 (image/png)

    + Headers

        Content-Length: 26572
leompeters
  • 886
  • 1
  • 13
  • 24