Git Product home page Git Product logo

shakedown's Introduction

shakedown

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

Example

Create test.sh:

#!/usr/bin/env 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:

$ ./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.

DSL

shakedown <VERB> <PATH> <CURL OPTIONS>
  <assertion>
  <assertion>
  ...

Assertions

status          <code>           Response status code = <code>
contains        <string>         Response body contains <string>
matches         <regex>          Response body matches <regex>
header          <string>         Response headers contains <string>
no_header       <string>         Response headers do not contain <string>
content_type    <string>         Content-Type header contains <string>
header_contains <name> <string>  Response header <name> contains <string>

HTTP Authentication

Use the -c option to provide credentials.

./test.sh -u my.domain.com -c user:pass

Setting cURL options

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

Exit code

The exit code is set to the number of failed tests.

Debugging

To help diagnose failing tests use print_headers, print_body, or make cURL verbose with '-v'.

More Examples

#!/usr/bin/env 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'

shakedown GET /about
  contains "$(cat about.html)" | head -n1         # because this is a bash script we can read files etc.

Environment variables

The environment variables SHAKEDOWN_URL and SHAKEDOWN_CREDENTIALS can be used instead of passing -u and -c options.

SHAKEDOWN_URL=https://duckduckgo.com ./test.sh

Request timeouts can be set with:

SHAKEDOWN_CONNECT_TIMEOUT=5  # sets the curl option --connect-timeout. defaults to 5 seconds.
SHAKEDOWN_MAX_TIME=30        # sets the curl option --max-time. defaults to 30 seconds.

Running tests in parallel

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

Docker

Push to DockerHub

https://hub.docker.com/r/robwhitby/shakedown

docker run -t -v "$PWD":/work robwhitby/shakedown /work/sample-test.sh -u https://duckduckgo.com

shakedown's People

Contributors

cammellos avatar johnmuth avatar robwhitby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

shakedown's Issues

no issue, just thank you

I've been using this app for ~4 years now and it still stuns me the simplicity, yet power I get out of of it. Thank you.

This is one of my crazy shakedowns (scrubbed)

#!/usr/bin/env bash
source shakedown.lib.20220531.bash

declare -A DIRECTIP
DIRECTIP['staging1.domain.io']='172.24.32.12'
DIRECTIP['staging2.domain.io']='172.24.32.9'
DIRECTIP['prodapp7.domain.io']='10.246.165.101'
DIRECTIP['prodapp8.domain.io']='10.246.165.20'

DIRECTIP['development.domain.io']='172.24.32.8'
DIRECTIP['integ.domain.io']='172.24.32.21'
DIRECTIP['integration.domain.io']='172.24.32.16'
DIRECTIP['testing1.domain.io']='172.24.32.18'
DIRECTIP['testing2.domain.io']='172.24.32.20'
DIRECTIP['testing3.domain.io']='172.24.32.19'
DIRECTIP['testing4.domain.io']='172.24.32.23'
DIRECTIP['testing5.domain.io']='10.246.165.62'
DIRECTIP['training.domain3.com']='172.24.32.13'

TESTURL=( "domain.com" "www.domain.com" )

# Color variables
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
# Clear the color after that
clear='\033[0m'

# Color variables
bg_red='\033[0;41m'
bg_green='\033[0;42m'
bg_yellow='\033[0;43m'
bg_blue='\033[0;44m'
bg_magenta='\033[0;45m'
bg_cyan='\033[0;46m'


# Loop each url on each host

for IP in "${!DIRECTIP[@]}"; do
  #echo $IP
  #echo ${DIRECTIP[$IP]}
  for URL in ${TESTURL[@]}; do
printf "\n\n${red}Testing${clear}: ${magenta}%s${clear}" "${IP}"
shakedown GET https://${URL} --resolve ${URL}:443:${DIRECTIP[$IP]} -k
  status 301
  header 'Location: https://www.domain2.com/gl/click.do?keycode=418259'
  done


done

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.