Add cleanup function to test scripts (#863)

This commit is contained in:
Ta-Ching Chen
2018-08-18 02:11:08 +08:00
committed by GitHub
parent d443f8b2ef
commit 2d01382a82
22 changed files with 339 additions and 99 deletions
+15 -4
View File
@@ -1,6 +1,20 @@
#!/bin/bash
set -euo pipefail
cleanup() {
log "Cleaning up..."
fission env delete --name python || true
fission fn delete --name $fn || true
rm -rf testDir-$fn || true
}
if [ -z "${TEST_NOCLEANUP:-}" ]; then
trap cleanup EXIT
else
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
fi
# 1. This test first creates a python function with a route
# 2. Makes a curl request to the route and verifies http.StatusOK is received.
# This step ensures the pod address is cached in router.
@@ -18,16 +32,13 @@ fission env delete --name python || true
log "Creating python env"
fission env create --name python --image $PYTHON_RUNTIME_IMAGE
trap "fission env delete --name python" EXIT
log "Creating hello.py"
mkdir testDir-$fn
printf 'def main():\n return "Hello, world!"' > testDir-$fn/hello.py
trap "rm -rf testDir-$fn" EXIT
log "Creating function " $fn
fission fn create --name $fn --env python --code testDir-$fn/hello.py
trap "fission fn delete --name $fn" EXIT
log "rm testDir-$fn"
rm -rf testDir-$fn
@@ -57,4 +68,4 @@ log "http_status: $http_status"
if [ "$http_status" -ne "200" ]; then
log "Something went wrong, http status after deleting function pod is $http_status"
exit 1
fi
fi