Skip to content

Commit

Permalink
Add whale examples to e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinvaneyk committed May 17, 2018
1 parent e8b96d7 commit a137c4f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 85 deletions.
70 changes: 0 additions & 70 deletions test/e2e/tests/bup_test_whales.sh

This file was deleted.

7 changes: 6 additions & 1 deletion test/e2e/tests/test_example_inputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ trap cleanup EXIT

fission fn create --name inputs --env workflow --src ${EXAMPLE_DIR}/inputs.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name inputs -b 'foobar' -H 'HEADER_KEY: HEADER_VAL' --method PUT | grep HEADER_KEY | grep HEADER_VAL | grep PUT | grep foobar
fission fn test --name inputs -b 'foobar' -H 'HEADER_KEY: HEADER_VAL' --method PUT \
| tee /dev/tty \
| grep -i Header_Val \
| grep HEADER_VAL \
| grep -i PUT \
| grep -q foobar
14 changes: 0 additions & 14 deletions test/e2e/tests/test_example_sleepalot.sh

This file was deleted.

119 changes: 119 additions & 0 deletions test/e2e/tests/test_whales.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

# Tests the whale examples in the examples/whales directory

set -euo pipefail

WHALES_DIR=$(dirname $0)/../../../examples/whales
BINARY_ENV_VERSION=latest

# TODO move to util file
# retry function adapted from:
# https://unix.stackexchange.com/questions/82598/how-do-i-write-a-retry-logic-in-script-to-keep-retrying-to-run-it-upto-5-times/82610
function retry {
local n=1
local max=5
local delay=5
while true; do
"$@" && break || {
if [[ ${n} -lt ${max} ]]; then
((n++))
echo "Command '$@' failed. Attempt $n/$max:"
sleep ${delay};
else
>&2 echo "The command has failed after $n attempts."
exit 1;
fi
}
done
}

cleanup() {
echo "cleaning up..."
set +e
fission fn delete --name whalesay
fission fn delete --name fortune
fission fn delete --name fortunewhale
fission fn delete --name echowhale
fission fn delete --name metadatawhale
fission fn delete --name nestedwhale
fission fn delete --name maybewhale
fission fn delete --name failwhale
fission fn delete --name foreachwhale
fission fn delete --name switchwhale
fission fn delete --name whilewhale
fission fn delete --name httpwhale
fission fn delete --name scopedwhale
}
trap cleanup EXIT

# Deploy required functions and environments
echo "Deploying required fission functions and environments..."
fission env create --name binary --image fission/binary-env:${BINARY_ENV_VERSION} || true
fission fn create --name whalesay --env binary --deploy ${WHALES_DIR}/whalesay.sh
fission fn create --name fortune --env binary --deploy ${WHALES_DIR}/fortune.sh

# Ensure that functions are available
retry fission fn test --name fortune

# test 1: fortunewhale - simplest example
echo "[Test 1]: fortunewhale"
fission fn create --name fortunewhale --env workflow --src ${WHALES_DIR}/fortunewhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name fortunewhale | tee /dev/tty | grep -q "## ## ## ## ##"

# test 2: echowhale - parses body input
echo "[Test 2]: echowhale"
fission fn create --name echowhale --env workflow --src ${WHALES_DIR}/echowhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name echowhale -b "Test plz ignore" | tee /dev/tty | grep -q "Test plz ignore"

# test 3: metadata - parses metadata (headers, query params...)
echo "[Test 3]: metadatawhale"
fission fn create --name metadatawhale --env workflow --src ${WHALES_DIR}/metadatawhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name metadatawhale -H "Prefix: The test says:" | tee /dev/tty | grep -q "The test says:"

# Test 4: nestedwhale - shows nesting workflows
echo "[Test 4]: nestedwhale"
fission fn create --name nestedwhale --env workflow --src ${WHALES_DIR}/nestedwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name nestedwhale | tee /dev/tty | grep -q "## ## ## ## ##"

# Test 5: maybewhale - shows of dynamic tasks
echo "[Test 5]: maybewhale"
fission fn create --name maybewhale --env workflow --src ${WHALES_DIR}/maybewhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name maybewhale | tee /dev/tty | grep -q "## ## ## ## ##"

echo "[Test 6]: failwhale"
fission fn create --name failwhale --env workflow --src ${WHALES_DIR}/failwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name failwhale | tee /dev/tty | grep -q "all has failed"

echo "[Test 7]: foreachwhale"
fission fn create --name foreachwhale --env workflow --src ${WHALES_DIR}/foreachwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name foreachwhale | tee /dev/tty | grep -q "[10,20,30,40,50]"

echo "[Test 8]: switchwhale"
fission fn create --name switchwhale --env workflow --src ${WHALES_DIR}/switchwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name switchwhale -b 'hello' | tee /dev/tty | grep -q "world"
fission fn test --name switchwhale -b 'foo' | tee /dev/tty | grep -q "bar"
fission fn test --name switchwhale -b 'acme' | tee /dev/tty | grep -q "right..."

echo "[Test 9]: whilewhale"
fission fn create --name whilewhale --env workflow --src ${WHALES_DIR}/whilewhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name whilewhale | tee /dev/tty | grep "5"

echo "[Test 10]: httpwhale"
fission fn create --name httpwhale --env workflow --src ${WHALES_DIR}/httpwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name httpwhale | tee /dev/tty | grep -q "## ## ## ## ##"

echo "[Test 11]: scopedwhale"
fission fn create --name scopedwhale --env workflow --src ${WHALES_DIR}/scopedwhale.wf.yaml
sleep 5 # TODO remove this once we can initiate synchronous commands
fission fn test --name scopedwhale | tee /dev/tty | grep -q "## ## ## ## ##"

0 comments on commit a137c4f

Please sign in to comment.