A tiny Bash DSL for HTTP testing with zero dependencies*.
Make HTTP requests and assert on the response body and headers.
* unless you count cURL and grep
Create test.sh
:
#!/bin/bash
source shakedown.sh # load the framework
shakedown GET /about # make a GET request
status 200 # assert response status is 200
content_type 'text/html' # assert Content-Type header contains string
header 'Expires' # assert response header exists containing string
contains 'Take back your privacy!' # assert response body contains string
shakedown POST / -d 'q=Shakedown' # make a POST request with form data
status 200
contains 'Bob Seger'
Run the tests against a base URL:
$ bash test.sh -u https://duckduckgo.com
Starting shakedown of https://duckduckgo.com
GET /about
✔ status 200
✔ Content-Type: text/html
✔ header Expires
✔ contains "Take back your privacy!"
POST /
✔ status 200
✔ contains "Bob Seger"
Shakedown complete. 2 passed, 0 failed.
shakedown <VERB> <PATH> <CURL OPTIONS>
<assertion>
<assertion>
...
status 'response status code'
contains 'string in response body'
matches 'regex in response body'
header 'string in response headers'
no_header 'no response header containing string'
content_type 'string in Content-Type header'
header_contains 'for a given header checks its value'
Use the -c option to provide credentials.
bash test.sh -u my.domain.com -c user:pass
Any parameters after the path are passed straight on to cURL.
e.g. To send form data, follow redirects and set verbose output.
shakedown POST /search -d 'query=shakedown' -L -v
The exit code is set to the number of failed tests.
To help diagnose failing tests use print_headers
, print_body
, or make cURL verbose with '-v'.
#!/bin/bash
source shakedown.sh # load the framework
shakedown GET /foo # make a GET request
status 404 # assert on http status code
content_type 'text/html' # assert Content-Type header contains string
contains 'Not found' # assert body contains string
matches 'No.*' # assert body matches regex
shakedown HEAD / # make a HEAD request
status 302
shakedown GET / -H 'Accept: application/json' # add curl options
print_headers # output response headers for debugging
print_body # output response body for debugging
status 200
header 'Expires'
shakedown PUT /user/1 -d name=Rob # make a PUT request
status 201
shakedown GET http://www.google.com -L # provide full url to override default base url.
status 200 # -L cURL option to follow redirects
shakedown GET http://www.google.com
header_contains 'Referrer-Policy' 'no-referrer' # assert header 'Referrer-Policy' contains value 'no-referrer'
The environment variables SHAKEDOWN_URL
and SHAKEDOWN_CREDENTIALS
can be used instead of passing -u and -c options.
SHAKEDOWN_URL=https://duckduckgo.com bash test.sh
Divide your tests into multiple files, then run those in parallel, for example:
export SHAKEDOWN_URL=https://duckduckgo.com
ls -1 test-*.sh | parallel bash