apiaryio / dredd Goto Github PK
View Code? Open in Web Editor NEWLanguage-agnostic HTTP API Testing Tool
Home Page: https://dredd.org
License: MIT License
Language-agnostic HTTP API Testing Tool
Home Page: https://dredd.org
License: MIT License
Just installed latest version via:
npm install -g git://github.com/apiaryio/dredd.git
Testing my API using:
dredd assets/public/blueprint.apib http://localhost:5000
Getting this error:
module.js:340
throw err;
^
Error: Cannot find module '../lib/parse-package-json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/prx/.nvm/v0.10.25/lib/node_modules/dredd/bin/dredd:3:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
NB: Not getting any error when using the "old" 0.1.7 version available on NPM
It's caused by old version of npm itself, just upate your npm globally with npm -g update npm
I'm trying to integrate dredd apiary tests into Jenkins. I followed these steps to install NodeJS, npm and dredd on Jenkins (on Linux):
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
While running the test I got this ERR message:
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the protagonist package,
npm ERR! not with npm itself....
Do you know this problem? Is there a solution for it? Thank you.
Mocha uses an event-based reporter structure, and it seems like dredd would benefit from this as well. This would make it easy to convert existing mocha reporters for use with dredd, while also making it easier to have different reporters report different data and add more metadata. (timing, especially, becomes easier with an event-driven design).
Our tests tend to fail only because the server has newer content ... could we add a switch that would tell dredd to test the structure only ? Seems like gavel has it ? Or is it there allready ?
thanks :)
I have an apiary.apib that has the following section:
### Log a user in [POST]
+ Request (application/json)
{ "username": "my_user_name", "password": "my_password" }
+ Response 200 (application/json)
+ Body
{
"data": {
"token": "234khsdfs9d8fsdf",
"expires": 1424641830
}
}
+ Schema
{
"type":"object",
"required":true,
"properties":{
"data": {
"type":"object",
"required":true,
"properties":{
"expires": {
"type":"number",
"required":true
},
"token": {
"type":"string",
"required":true
}
}
}
}
}
Note that the "expires" property is specified as a number the the schema, and in the example, the "expires" property clearly shows a number.
I wrote a simple instance that implements this part of the api design, except that my implementation explicitly returns a string for "expires". This passes all dredd tests.
I would expect any tests regarding this resource to fail, when the type of the actual differs from the type of the expected
Is there a solution for
apiaryio/snowcrash#56
?
due to the inserted \n, comparing text/plain will always fail the dredd test.
Here's my transaction in the after hook
{ name: 'GET animals > Via id > Retuning text',
id: 'GET /animals/G1234',
host: 'localhost',
port: '3000',
request:
{ body: '{}\n',
headers:
{ Accept: 'text/plain',
'content-type': 'text/plain',
'User-Agent': 'Dredd/0.3.1 (Darwin 13.1.0; x64)',
'Content-Length': 3 },
uri: '/animals/G1234',
method: 'GET' },
expected:
{ headers: { 'Content-Type': 'text/plain' },
**body: 'G1234\n',**
statusCode: '200' },
fullPath: '/animals/G1234',
real:
{ statusCode: 200,
headers:
{
'content-type': 'text/plain',
'content-length': '5',
connection: 'keep-alive' },
**body: 'G1234'** } }
and my markdown is simply
+ Response 200 (text/plain)
```
G1234
```
Hi guys,
I've managed to make dredd-example work on my Mac, but when I try the same on a Linux box, it fails and I can't find the reason for it. If I type, for instance, dredd --help it simply returns to the prompt, no error message but no help either.
I am not sure where to look and find some sort of error log, can you give me any tips on that?
Both multiparty and parted (nodejs body parsing middlewares) do not accept Dredd generated multiform posts, due to line endings not being OK.
It seems they should be \r\n and Dredd always sends \n (perhaps because API Blueprint only supports that, so that's the actual data it's told to send).
So, feature request:
Dredd should make sure that the request are formatted decently. (:
Example request:
+ Request (multipart/form-data;boundary=---BOUNDARY)
+ Headers
Authorization: qwertyqwerty
+ Body
---BOUNDARY
Content-Disposition: form-data; name="json"
{"name":"test"}
---BOUNDARY
Content-Disposition: form-data; name="image"; filename="filename.jpg"
Content-Type: image/jpeg
data
---BOUNDARY--
(See also: apiaryio/api-blueprint#100)
Hi. I am getting call stack size exceeded with larger json responses. It seems there is no option to make stack size larger?
Example blueprint: http://docs.apiblueprintapi.apiary.io/ Possibly related to #25.
I try to use following command to test my api
$ dredd jobs.md drupal/daxuebao/api
info: Beginning Dredd testing...
complete: Tests took 7ms
actually the job.md is empty file..
So I write some api to this file:
# GET /views/jobs?args[0]={id}
+ Parameters
+ id (required, number, `1`) ... Numeric `id` of the Note to perform action with. Has example value.
+ Response 200
+ Body
[{"title":"Abluo Aptent Uxor","author":"thispedacesp","company":"Abigo bene defui ..........
for clearly read, I delete some response body.
But still:
info: Beginning Dredd testing...
complete: Tests took 7ms
$ dredd jobs.md drupal/daxuebao
info: Beginning Dredd testing...
complete: Tests took 7ms
$ dredd jobs.md xxx/whatever
info: Beginning Dredd testing...
complete: Tests took 7ms
so ... what's wrong?
I'm trying to use Basic Auth in our specification, adding a header like this:
### Retrieve list of entities [GET]
+ Parameters
+ nation (optional, string, `US`) ... The nationality of the entities returned.
+ Request
+ Header
```
"Authorization": "Basic YmVuOnBhc3M="
```
+ Response 200 (application/json)
[Entities][]
But this causes this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (http.js:1472:15)
at Socket.socketOnEnd [as onend] (http.js:1568:23)
at Socket.g (events.js:180:16)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
Does Dredd support authorization headers, or am I doing it wrong?
Right now, these flags aren't respected throughout the app if using Dredd's js api.
This is an issue with the cli library's configuration, and could be easily solved by switching to something like winston for internal logging.
Even better would be to have the app generate events, which are then logged somewhere, so that the app isn't littered with log statements.
Currently hooks have to be applied to a specific transaction.
It would be useful to have "global" hooks that execute before each test, something like this:
before "ALL", (transaction) ->
console.log 'Displayed before each test'
For now I am working around this limitation by calling runHooksForTransaction two more times (once for before and once for after) in add-hooks.js and passing in a fake transaction name of "ALL".
runner.before('executeTransaction', function(transaction, callback) {
return runHooksForTransaction(hooks.beforeHooks['ALL'], transaction, callback);
});
I installed dredd - API Blueprint Testing Tool and trying to test our APIary API against the implementation.
In the blueprint I have just one resource which is correctly implemented on somehost... but test fails :(
test command: dredd apiary.apib http://somehost.de:8443/imp-endpoint
output: Info: Beginning Dredd testing... undefined
I tried also with more options to get more information what is undefined.. like -l verbose and some other options. But I did not get more information about the failure :( Does anyone have experience with it? Thank you!!! :)
platform - win, dredd - v0.2.1, test apib: https://www.dropbox.com/s/p9zexrj3g6htzlq/apiary.apib, test.sh: https://www.dropbox.com/s/vqn6gch91vwqc16/test.sh
on stackoverflow: http://stackoverflow.com/questions/21881988/dredd-api-blueprint-testing-tool-undefined-issue
In order to prevent issues like #6 cover CLI interface and npm install -g dredd
workflow with integration tests.
When making a request with the following blueprint:
+ Request
X-Access-Token: aBcDeFg
The resulting dredd request DOWNCASES the value. The case matters!
request:
{
"host": "localhost",
"port": null,
"path": "/test",
"method": "GET",
"headers": {
"X-Access-Token":"abcdefg",
"User-Agent": "Dredd/0.1.7 (Darwin 13.0.0; x64)"
}
}
Add tests to cover all CLI parameters. Consider rewriting of CLI executable to Coffee and include the build of dredd
executable in the build process.
If you run with -r markdown -o ~/test.md
, dredd exits with an error similar to:
error: errno=34, code=ENOENT, path=/current-working-directory/Users/evan/test.md
It appears that multiple responses aren't supported. This limits the usefulness of dredd
when using something like grunt
or guard
.
My use case is creating a subscriber, when a subscriber is created successfully 200. When it's a duplicate it's a 422. First test will create the subscriber and all subsequent tests will fail
$ dredd apiary.apibp http://localhost:3000/
INFO: Runtime compilation warning: Multiple responses, using first.
on > Subscribers > Creating a Subscriber
Not sure if this is intentionally, but the published version on NPM is for 0.1.7, one release after the tags stop (at 0.1.6). I'll close this if this is intended, otherwise, I'd like to ask for tag updates for NPM.
Hi,
I'd like to find way how to run Dredd programatically e.g. from Grunt task.
A
Scripts in the /scripts
are *nix (OS X)-only.
The goal is to provide the functionality on Windows so I can run
$ npm install
$ npm test
On Windows as well.
https://www.npmjs.org/doc/misc/npm-scripts.html
Related to #47
When fetching a resource with ID, is there a way for dredd to pick up a default or example ID for testing? SO(http://stackoverflow.com/questions/22099711/how-test-show-index-request-with-dredd-rails?newreg=d5b850c5921e41338dbfd7b144060a4a) mentioned the example value gets picked up, but that's not working for me. I also tried specifiying a valid value, but that doesn't get picked up either.
...
171904f7-a0e8-455e-ab09-8671f3224d6a
) ... id
is the UUID created at resource creation.
171904f7-a0e8-455e-ab09-8671f3224d6a
request:
host: xxx.com
port: null
path: /images/ <-- expected ID to show up here!
method: GET
headers:
User-Agent: Dredd/0.2.1 (Darwin 13.0.2; x64)
Dredd installed correctly, however when running any dredd command it immediately fails and outputs ERROR: Could not detect dredd version.
This error seems to stem from the cli
dependency (here: https://github.com/chriso/cli/blob/32c7013716c3cb5ce1cdf5486aacb26fb84c2d48/cli.js#L529) which implies that it's having trouble finding the package.json
file. I do, however, see a package.json
file if I navigate to the install path (/usr/local/lib/node_modules/dredd/package.json
)
npm 1.3.11
node 0.10.21
I'm unable to make Dredd work with Rails out of the box. The issue seems to be related to how Rails parses json and relies on content-length to be set.
It would be great if Dredd implicitly added Content-Length
based on the body for POST
requests.
There's a git repo with failing and succeeding API descriptions here:
https://github.com/theodorton/dredd-test-rails
it doesn't appear that dredd leverages http_proxy or https_proxy when doing it's web calls to the API endpoint.
When running dredd multiple times with the -r markdown -o report.md
flags, old reports are deleted rather than being truncated and written over as if in w+
write mode.
This file deletion baffles my live markdown previewer, which I use to view the report in between runs. Keeping the file but replacing it's contents should it exist would certainly assist my workflow, and perhaps others'.
If I have an api endpoint documented with api blueprint and expect a response code of 200, and when dredd runs against that endpoint it produces a non-200 response code, dredd still marks the test as passing. Right now I can get around this through checking the response body, which does differ, but it would be nice if the response code was strictly checked as well.
Most of the testing tools distinguish between assertion failures
and test errors
.
This should be reflected in dredd as well.
In my current API there are queries which I would like to skip, is this possible or do I have to remove these from documentation ?
Example: queries which are not implemented currently
Having the following in a Parameters section:
+ Parameters
+ filter (required, string, `id~(valueOne|valueTwo)`) ... Includes all items which match the filter.
causes dredd to report "Ambigous URI template: theUrl{?filter}. Parameter not defined:'filter' on theTestName.
Removing the closing parenthesis from within the example value makes it work, but of course that doesn't make the underlying service happy. I'm documenting an already-existing API, so I can't change the format of the parameter. I suspect that the parameter parsing is looking for the first )
without noticing that it's within the example value (back-ticks).
I want to be able to create an entity and use returned entity ID in next action as a URI parameter. Example blueprint can be found here
Hey, was just playing with this from the blog post http://blog.apiary.io/2013/10/17/How-to-test-api-with-api-blueprint-and-dredd/]. I'm trying to get dredd to fail when the response body is different.
I expect
body:
[
{
"_id": "52341870ed55224b15ff07ef",
"type": "bulldozer",
"name": "willy"
},
{
"_id": "12345",
"type": "car",
"name": "tommy"
}
]
but if I actually get back
body:
[
{
"_id": "12345",
"type": "car",
"name": "tommy"
}
]
the test still passes.
Is this expected?
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
body: The ... property is required.
(no schema specified)
It would be great to have a documentation and some examples how to use Dredd's JS API e.g. in the Grunt task. Related to #4
Exit status is 0 although some step is failing. Exit status should be > 0 if tests are not passing.
Try to npm install -g dredd
, but alert me:
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/ParserCore.o
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/Serialize.o
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/SerializeJSON.o
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/SerializeYAML.o
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/snowcrash.o
CXX(target) Release/obj.target/libsnowcrash/snowcrash/src/posix/RegexMatch.o
LIBTOOL-STATIC Release/snowcrash.a
CC(target) Release/obj.target/sundown/snowcrash/sundown/src/autolink.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/src/buffer.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/html/houdini_href_e.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/html/houdini_html_e.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/html/html.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/html/html_smartypants.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/src/markdown.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/src/stack.o
CC(target) Release/obj.target/sundown/snowcrash/sundown/src/src_map.o
LIBTOOL-STATIC Release/sundown.a
CXX(target) Release/obj.target/protagonist/src/annotation.o
In file included from ../src/annotation.cc:1:
In file included from ../src/protagonist.h:1:
/Users/tangmonk/.node-gyp/0.10.21/src/node.h:61:10: fatal error: 'uv.h' file not found
#include "uv.h"
^
1 error generated.
make: *** [Release/obj.target/protagonist/src/annotation.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.1.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/dredd/node_modules/protagonist
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
example:
dredd non_existent_file.md http://localhost:3000
$ echo $?
0
Example (bellow) is that if I want to check that the result is correct, I will change the status code to some other number, to actually make sure that dredd throws and error saying something went wrong.
If I change the status code to another number, the following reports as passing. Note there are not semantic errors with in the file, verified with online editor.
+ Response 410 (application/json)
+ Body
{
"status": "410"
}
Running dredd apiary.apib http://myapp.apiary-mock.com
fails unexpectedly.
Here is extract of report.
diff is in headers.
Is that normal ?
uri: /services
method: POST
expected:
headers:
Content-Type: application/json
body:
{
"id": 3
"asker_id": "615",
"title": "Cuisinier asiatique",
"description": "Pour vos gouters d'anniversaire, essayez mes nems au chocolat.",
"deadline": "2014-08-16T00:00:00+02:00",
"lat": "48.791960590116",
"lng": "2.457136139274",
"address": "12 rue Martel, Paris, France",
"category_id": 5,
"unit_price": "12.0",
"pricing_unit": "unit",
"state": "open",
"created_at": "2014-03-30T15:23:47+02:00",
"updated_at": "2014-07-30T15:23:47+02:00"
}
statusCode: 201
actual:
statusCode: 201
headers:
content-type: application/json
date: Tue, 15 Apr 2014 14:42:38 GMT
x-apiary-ratelimit-limit: 120
x-apiary-ratelimit-remaining: 116
x-apiary-transaction-id: 534d455e84eb780200001b00
transfer-encoding: chunked
connection: keep-alive
body:
{
"id": 3
"asker_id": "615",
"title": "Cuisinier asiatique",
"description": "Pour vos gouters d'anniversaire, essayez mes nems au chocolat.",
"deadline": "2014-08-16T00:00:00+02:00",
"lat": "48.791960590116",
"lng": "2.457136139274",
"address": "12 rue Martel, Paris, France",
"category_id": 5,
"unit_price": "12.0",
"pricing_unit": "unit",
"state": "open",
"created_at": "2014-03-30T15:23:47+02:00",
"updated_at": "2014-07-30T15:23:47+02:00"
}
My api serves images inline, so the body contains actual data instead of json. In this case, I only want to validate that a non-0 body size is returned with the expected content type.
Hi, I've executed:
dredd ./apiary.apib http://127.0.0.1:3000
Segmentation fault
I don't know what exactly is happening, but when I'm installing dredd, I'ge git some warnings like,...
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
npm WARN engine [email protected]: wanted: {"node":"0.8.x"} (current: {"node":"v0.10.21","npm":"1.3.11"})
Please I hove you can help me.
Best Regards.
Curious whether you guys have this in your roadmap as a future improvement.
For example:
dredd path/to/blueprint/files/**/*.md http://localhost:8080/api
Hi,
Im trying to run dredd tests with command line:
dredd apiary.apib http://localhost:8080/api/v2
but its seems from backend logs that it tries to connect to http://localhost:8080.
And if for example in apiary.apib I have:
Smth [/smth/{smthId}]
tests tries to reach url: http://localhost:8080/smth/12345
but should reach url: http://localhost:8080/api/v2/smth/12345
I tried also with:
dredd apiary.apib http://localhost:8080/api/v2/
( slash at the end ) but no change.
What Im doing wrong ? or its some problem with dredd.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.