-
Notifications
You must be signed in to change notification settings - Fork 280
Dredd testing of APIary calls returning an image / PNG #87
Comments
Related: #52 |
Thanks for the report. We 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 |
Has there been any updates with regards to this? The workaround mentioned in #52 doesn't seem to work any longer, but I haven't seen any mention of binary responses being supported in the API Blueprint format either. Am I missing something, or is this still not supported? Thanks! |
Well, another workaround, which is working for me, is to modify the transaction in a preValidation hook:
Probably not ideal, but only solution I've been able to come up with so far. |
@jaydiablo I think that would be a preferred workaround as of now. Not sure how the original workaround scenario is handled now, but I'd say hooks are the way to go and should work even in the future. Regarding out of the box support for binary files, this all boils down to apiaryio/api-blueprint#20, i.e. support for external assets in the API Blueprint language. Feel free to subscribe to the issue or contribute with ideas/opinions. API Blueprint has a public roadmap and at the time of writing this post, the "External Assets" is number 6 top priority. |
+1 to @jaydiablo with Content-Length header > 1 |
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 Now, I am looking for an example to a POST request to send an image... :P |
I use the following DREDD version:
@leomperes : I tried to set the content-length like you suggested as a workaround but the problem still shows up in DREDD 😞 I installed DREDD this morning - do I need to use a different version?
|
@markfink Hi, current version of Dredd, i.e. v1.1.0, should work with the workaround. Do hooks work for you the way they're documented in http://dredd.readthedocs.io/en/latest/hooks/ ? |
@honzajavorek the hook workaround works fine but I can't fix this by providing content-length or other image/png related headers like @leomperes suggested in above post. |
@markfink I don't have time right at this moment to test out the thing, but using See http://dredd.readthedocs.io/en/latest/how-it-works/#automatic-expectations |
Hey @markfink, try to use the code below on your hook to make your expected empty body equals to the real: switch (transaction.expected.headers['Content-Type']) {
// case 'text/plain; charset=UTF-8':
// case 'text/html; charset=utf-8':
case 'image/png':
transaction.expected.body =
transaction.expected.body.replace(/^\s+|\s+$/g, '');
} |
Just a note: You don't need to disable the entire test for the action, though. You can just disable validation for some particular response body and let Dredd validate only headers with this simple workaround: #510. |
Is there a solution for this? I'm having the same problem, my expected response has no body because I have no way to set the image there, and in actual response body it comes with an image like this: And more and more digits... So how I can workaround this? What's the trick? |
Reminder: work in #836 should be considered once we're working on binary files support. |
While this was resolved for a while since the moment we fixed working with empty responses, in #1094 this is going to get proper tests, examples, and docs. Thank you all in participating here! It was really helpful. |
…-examples-minim Rewrite detectTransactionExamples to minim
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^��
http://stackoverflow.com/questions/24824867/dredd-testing-of-apiary-calls-returning-an-image-png
The text was updated successfully, but these errors were encountered: