Giter Site home page Giter Site logo

Comments (16)

jaydiablo avatar jaydiablo commented on May 22, 2024 2

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.

Pablodotnet avatar Pablodotnet commented on May 22, 2024 1

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.

honzajavorek avatar honzajavorek commented on May 22, 2024 1

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.

honzajavorek avatar honzajavorek commented on May 22, 2024

Related: #52

from dredd.

Almad avatar Almad commented on May 22, 2024

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.

jaydiablo avatar jaydiablo commented on May 22, 2024

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.

honzajavorek avatar honzajavorek commented on May 22, 2024

@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.

leompeters avatar leompeters commented on May 22, 2024

+1 to @jaydiablo with Content-Length header > 1

from dredd.

leompeters avatar leompeters commented on May 22, 2024

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.

markfink avatar markfink commented on May 22, 2024

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.

honzajavorek avatar honzajavorek commented on May 22, 2024

@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.

markfink avatar markfink commented on May 22, 2024

@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.

honzajavorek avatar honzajavorek commented on May 22, 2024

@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.

leompeters avatar leompeters commented on May 22, 2024

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, '');
}

Source: http://dredd.readthedocs.io/en/latest/hooks-nodejs/#remove-trailing-newline-character-in-expected-plain-text-bodies

from dredd.

netmilk avatar netmilk commented on May 22, 2024

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.

honzajavorek avatar honzajavorek commented on May 22, 2024

Reminder: work in #836 should be considered once we're working on binary files support.

from dredd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.