Skip to content

Commit

Permalink
test/runexamples: Reorg. Add non-continue fail test.
Browse files Browse the repository at this point in the history
Restructure the cmd construction so that the bare and dockerized
versions have more similar arguments.

Add a third argument to `check` that takes additional options to pass to
dctest. Hoist --continue-on-error to be passed using this option and add
an additional faiure test without the option.
  • Loading branch information
kanaka committed Nov 15, 2024
1 parent 6b904fd commit febad03
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions test/runexamples
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
PROJECT=${PROJECT:-${USER}}
DCTEST_IMAGE=${DCTEST_IMAGE}

repo_root=$(dirname $(readlink -f "${0}"))/..
examples_dir=${repo_root}/examples
repo_root=$(realpath $(dirname $(realpath "${0}"))/..)

results_dir=$(mktemp -d)

dc() { docker compose -p ${PROJECT} -f ${examples_dir}/docker-compose.yaml "${@}"; }
dc() { docker compose -p ${PROJECT} -f ${repo_root}/examples/docker-compose.yaml "${@}"; }
up() { dc up -d; }
down() { dc down; }
down() { dc down -t1; }

fail() {
msg=${1}
Expand All @@ -22,21 +21,19 @@ fail() {
check() {
passed=${1}; shift
failed=${1}; shift
opts=${1}; shift
example_files=${@}

if [ -z "${DCTEST_IMAGE}" ]; then
cmd="${repo_root}/dctest --continue-on-error --results-file ${results_dir}/results.json ${PROJECT}"
for example in ${example_files}; do
cmd="${cmd} ${examples_dir}/${example}"
done
else
cmd="${repo_root}/dctest"
if [ "${DCTEST_IMAGE}" ]; then
cmd="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock"
cmd="${cmd} -v ${repo_root}/examples/:/app/examples -v ${results_dir}/:/app/results"
cmd="${cmd} ${DCTEST_IMAGE} --continue-on-error --results-file /app/results/results.json ${PROJECT}"
for example in ${example_files}; do
cmd="${cmd} /app/examples/${example}"
done
cmd="${cmd} -v ${repo_root}/:${repo_root}:ro -v ${results_dir}/:${results_dir}"
cmd="${cmd} ${DCTEST_IMAGE}"
fi
cmd="${cmd} ${opts} --results-file ${results_dir}/results.json ${PROJECT}"
for example in ${example_files}; do
cmd="${cmd} ${repo_root}/examples/${example}"
done

echo "Running: ${cmd}"
${cmd}
Expand All @@ -59,12 +56,18 @@ check() {
}


[ "${repo_root}" ] || fail "repo_root cannot be empty"
[ "/" = "${repo_root}" ] && fail "repo_root cannot be '/'"

# TESTS

copt="--continue-on-error"

up

check 5 0 00-intro.yaml
check 6 4 00-intro.yaml 01-fails.yaml
check 12 0 02-deps.yaml
check 5 0 "${copt} " 00-intro.yaml
check 6 4 "${copt} " 00-intro.yaml 01-fails.yaml
check 5 1 " " 00-intro.yaml 01-fails.yaml
check 12 0 "${copt} " 02-deps.yaml

down

0 comments on commit febad03

Please sign in to comment.