Skip to content

Commit

Permalink
Tidy up shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Dec 27, 2023
1 parent a047332 commit e9cac1f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
12 changes: 7 additions & 5 deletions test-browser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ PORT=8000
DOWNLOADS=~/Downloads
PIDFILE=/tmp/http-cache-test-server.pid

function usage {
if [[ -n "${1}" ]]; then
echo "${1}"
fi
echo "Usage: $0 [ browser-name ... ]" >&2
}

function run {
BROWSERS=( "$@" )

Expand Down Expand Up @@ -72,11 +79,6 @@ function test_browser {

}

function usage {
echo "${1}"
echo "Usage: $0 [ browser-name ... ]" >&2
}

if [[ $# -eq 0 ]]; then
run safari firefox chrome
else
Expand Down
15 changes: 9 additions & 6 deletions test-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

PIDFILE=/tmp/http-cache-test-server.pid


ALL_PROXIES=(squid nginx apache trafficserver varnish caddy nuster)
DOCKER_PORTS=""
for PORT in {8001..8006}; do
DOCKER_PORTS+="-p ${PORT}:${PORT} "
done

function usage {
if [[ -n "${1}" ]]; then
echo "${1}"
fi
echo "Usage: $0 [ -i test_id ] [ proxy... ]"
}

function run {
TEST_ID="$1"
shift
Expand All @@ -19,7 +25,7 @@ function run {
npm run --silent server --port=8000 --pidfile=$PIDFILE &

# run proxies container
docker run --platform linux/amd64 --name=tmp_proxies ${DOCKER_PORTS} -dt mnot/proxy-cache-tests host.docker.internal \
docker run --platform linux/amd64 --name=tmp_proxies "${DOCKER_PORTS}" -dt mnot/proxy-cache-tests host.docker.internal \
> /dev/null

# run nuster container
Expand Down Expand Up @@ -83,7 +89,7 @@ function test_proxy {
;;
esac

echo "* ${PKG} $(docker container exec tmp_proxies /usr/bin/apt-cache show $PKG | grep Version)"
echo "* ${PKG} $(docker container exec tmp_proxies /usr/bin/apt-cache show ${PKG} | grep Version)"

if [[ -z "${TEST_ID}" ]]; then
npm run --silent cli --base=http://localhost:${PROXY_PORT} > "results/${PROXY}.json"
Expand All @@ -92,9 +98,6 @@ function test_proxy {
fi
}

function usage {
echo "> $0 [ -i test_id ] [ proxy... ]"
}

TEST_ID=""
while getopts "h?i:" opt; do
Expand Down
47 changes: 36 additions & 11 deletions test-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@

## Run tests against a host/port combination.


function usage {
echo "${1}"
echo "Usage: ${0} host[:port] [ test-id ]" >&2
exit 1
if [[ -n "${1}" ]]; then
echo "${1}"
fi
echo "Usage: ${0} [ -i test-id ] host[:port]"
}

function run {
TEST_ID="$1"
HOST="$2"
if [[ -z $TEST_ID ]]; then
npm run --silent cli --base="http://${HOST}"
else
npm run --silent cli --base="http://${HOST}" --id="${TEST_ID}"
fi

}

if [[ $# -eq 0 ]]; then
TEST_ID=""
while getopts "h?i:" opt; do
case "${opt}" in
h)
usage
exit 0
;;
i)
TEST_ID=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))

if [[ $# -ne 1 ]]; then
usage "Please specify a host:port."
exit 1
fi

# run tests
if [[ -z $2 ]]; then
npm run --silent cli --base="http://${1}"
else
npm run --silent cli --base="http://${1}" --id="${2}"
fi
run "$TEST_ID" "$1"

0 comments on commit e9cac1f

Please sign in to comment.