Your typical bash script for smoke testing a microservice would start:
#!/bin/bash
set -e
[[ ! -z "$DEBUG" ]] && set -x
trap "exit" INT
CURL_RETRY="--retry 3 --retry-delay 5"
# because curl retry doesn't happen on "Connection refused", i.e. when a dependency isn't up yet
sleep $CURL_INITIAL_WAIT
curl $CURL_RETRY -f http://my-service/
curl $CURL_RETRY -I http://my-service/nonexistent | grep "404"
curl $CURL_RETRY -f http://my-service/page | grep -v "/[Pp]age title/"
Works great with for example build-contract, but with limitations:
- Quite a bit of boilerplate for every script.
- Assertion errors are really just errors. With teting libs you'd expect to see what the actual result was.
Put a bunch of test scripts named *.sh
in ./test
and...
docker run --rm -v $(pwd)/test:/test -e DEBUG=y -e CURL_INITIAL_WAIT=1 -e CURL_RETRY="--retry 2 --retry-delay 3" yolean/crep
echo "$? == 0 means success"
Or to avoid volumes - recommended because it works with Docker over tcp - use a Dockerfile
like
FROM yolean/crep
COPY test /test
# Or put these in docker-compose.yml, or just omit them and use defaults
ENV DEBUG y
ENV CURL_INITIAL_WAIT 1
ENV CURL_RETRY "--retry 2 --retry-delay 3"
docker build -t yolean/crep .
Publish to https://hub.docker.com/r/yolean/crep/