Comments (16)
Well, another workaround, which is working for me, is to modify the transaction in a preValidation hook:
hooks.beforeValidation("Machines > Machines collection > Get Machines", function (transaction) {
transaction.real.body = '';
});
Probably not ideal, but only solution I've been able to come up with so far.
from dredd.
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:
body:
����JFIF``��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), quality = 90
��C
�ޣ9�խ#�E�ʹ�h����g�?���s��g���X�{
And more and more digits... So how I can workaround this? What's the trick?
from dredd.
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.
from dredd.
Related: #52
from dredd.
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
from dredd.
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!
from dredd.
@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.
from dredd.
+1 to @jaydiablo with Content-Length header > 1
from dredd.
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
from dredd.
I use the following DREDD version:
$dredd --version
dredd v1.1.0
@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?
body: Real and expected data does not match.
...
body:
�PNG
from dredd.
@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/ ?
from dredd.
@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.
from dredd.
@markfink I don't have time right at this moment to test out the thing, but using before
hook for setting relevant bodies/headers to the same values for real
and expected
should generally work, regardless the intention. Also, HTTP headers should be checked just for presence (i.e. whatever headers are in expected
, need to be present also in real
). If it doesn't work, then it smells like bug 👀
See http://dredd.readthedocs.io/en/latest/how-it-works/#automatic-expectations
from dredd.
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, '');
}
from dredd.
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.
from dredd.
Reminder: work in #836 should be considered once we're working on binary files support.
from dredd.
Related Issues (20)
- Package dependency triggers NPM advisory (1179) HOT 5
- [Question] How to send form-data (not file, it's string)? HOT 1
- Skipped tests when using square brackets in get parameter name HOT 5
- Package dependency triggers NPM advisory (1696) HOT 1
- [Suggestion] Add timeout
- vulnerability CVE-2020-7598 is introduced by package minimist HOT 1
- dredd init fails when travis ci integration is requested HOT 1
- API description parser error
- oneOf doesn't work as expected
- [Question] Is it possible to split hooks.js?
- Update latest image on Dockerhub
- Add the ability to issue warnings instead of errors for hyphens in Openapi request parameters.
- Dredd doesn't make consistency check between OpenAPI schema and example
- Improved documentation for running dredd in CI / docker
- Empty body with x-www-form-urlencoded
- Multiple status code exclusion in if statement in webhook
- Issues on Paramaeters Example with Swagger.JSON
- Request library is deprecated
- Head type requests not working HOT 1
- Is `dredd` dead? Please don't abandon this amazing project! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dredd.