-
Notifications
You must be signed in to change notification settings - Fork 280
Verify whether Dredd handles binary data #1094
Conversation
7e6109b
to
7e5bf31
Compare
1b096f0
to
d5414b3
Compare
73f458f
to
1965d9f
Compare
Normalize 'multipart/form-data' bodies for both API Blueprint and Swagger, avoid ignoring falsy values at multiple places (URI parameters, x-example)
a62adda
to
3d396f6
Compare
src/performRequest.js
Outdated
|
||
try { | ||
httpOptions.body = getBodyAsBuffer(transactionReq.body, transactionReq.bodyEncoding); | ||
httpOptions.headers = setContentLength(transactionReq.headers, httpOptions.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that setContentLength
is a little bit misleading here, normalizeHeaders
or something like that would be more fitting in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't interfere with any other headers. It detects the name of the content-length header if it exists, and sets it to the correct value. In case it doesn't exists, it adds the header. IMHO the name is right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalizeContentLengthHeader
then Q___(-_-)Q
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/performRequest.js
Outdated
return 'base64'; | ||
} | ||
throw new Error(`Unsupported encoding: '${encoding}' (only UTF-8 and ` | ||
+ 'Base64 are supported)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would personally use switch
instead if
(s) wherever possible, something like:
switch (lcEncoding) {
case 'utf-8':
case 'utf8':
return 'utf-8'
case 'base64';
return 'base64';
default:
throw new Error(`Unsupported encoding: '${encoding}' (only UTF-8 and `
+ 'Base64 are supported)');
}
But it is not an issue, just an idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll trust you this is more javascriptonic 😄 Python doesn't have switch
so I never think of using it, even in situations where it probably makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/performRequest.js
Outdated
performRequest.getBodyAsBuffer = getBodyAsBuffer; | ||
performRequest.setContentLength = setContentLength; | ||
performRequest.createTransactionRes = createTransactionRes; | ||
performRequest.detectBodyEncoding = detectBodyEncoding; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we are exposing private/internal APIs for testing purposes, I think it would be good idea to prefix the names with leading underscores __
- see this for inspiration 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol (inspiration). I did some research and dropped some thoughts on this to apiaryio/dredd-transactions#179 (comment). Let's continue there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👍. Just a few comments, I'll leave it up to you whether you decide to make changes or not.
@michalholasek Addressed your comments. Would you mind looking at the additional commits and saying 👍 or 👎 ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
🚀 Why this change?
This is to close the Epic: empty responses and binary files epic. Since the empty responses have been fixed, it is (probably!) already possible to test binary data with Dredd or to easily skip the testing. However, this isn't verified in Dredd's test suite and there are no examples in the docs.
🚧 To Do
📝 Related issues and Pull Requests
✅ What didn't I forget?
npm run lint