Skip to content

Commit

Permalink
Allow specifying complete URLs to override the base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
robwhitby committed Oct 18, 2015
1 parent 42d4031 commit 03c4dc0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
@@ -1,9 +1,11 @@
# shakedown

A tiny Bash DSL for HTTP testing.
A tiny Bash DSL for HTTP testing with zero dependencies.

Make HTTP requests and assert on the response body and headers.

<sub>* unless you count cURL and grep</sub>


## Example
Create `test.sh`:
Expand Down Expand Up @@ -101,6 +103,9 @@ shakedown GET / -H 'Accept: application/json' # add curl options

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
```


Expand Down
14 changes: 14 additions & 0 deletions sample-test.sh
@@ -0,0 +1,14 @@
#!/bin/bash
source shakedown.sh # load the framework

shakedown GET /about # make a GET request
status 200 # assert response status is 200
header 'Content-Type: text/html' # assert response header exists
contains 'Take back your privacy!' # assert resposne body contains string

shakedown POST / -d 'q=Shakedown' # make a POST request with form data
status 200
contains 'Bob Seger'

shakedown GET http://www.google.com -L # provide full url to override default base url.
status 200 # -L cURL option to follow redirects
8 changes: 5 additions & 3 deletions shakedown.sh
Expand Up @@ -38,7 +38,7 @@ if [ -n "${CREDENTIALS}" ]; then
AUTH="--anyauth --user ${CREDENTIALS}"
fi

CURL="curl -sS ${AUTH} -D ${RESPONSE_HEADERS} --connect-timeout 5 --max-time 10"
CURL="curl -sS ${AUTH} -D ${RESPONSE_HEADERS} --connect-timeout 5 --max-time 30"

CRED=$(tput setaf 1)
CGREEN=$(tput setaf 2)
Expand Down Expand Up @@ -85,16 +85,18 @@ shakedown() {
_start_test
METHOD="$1"
URL="$2"
if ! [[ $URL == http* ]]; then
URL="${BASE_URL}${URL}"
fi
echo
echo "${METHOD} ${URL}"
METHOD_OPT="-X ${METHOD}"
if [ "${METHOD}" = "HEAD" ]; then
METHOD_OPT="-I"
fi
${CURL} ${METHOD_OPT} "${@:3}" "${BASE_URL}${URL}" > ${RESPONSE_BODY}
${CURL} ${METHOD_OPT} -v "${@:3}" "${URL}" > ${RESPONSE_BODY}
}


# assertions

header() {
Expand Down

0 comments on commit 03c4dc0

Please sign in to comment.