Test framework improvement (#1128)
This commit is contained in:
committed by
Ta-Ching Chen
parent
1e8dfa38da
commit
c3177f9ebd
@@ -1,30 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
|
||||
ROOT=$(dirname $0)/../..
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
fn=testnormal-$(date +%s)
|
||||
fn_secret=testsecret-$(date +%s)
|
||||
fn_cfgmap=testcfgmap-$(date +%s)
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
env=python-$TEST_ID
|
||||
fn=testnormal-$TEST_ID
|
||||
fn_secret=testsecret-$TEST_ID
|
||||
fn_cfgmap=testcfgmap-$TEST_ID
|
||||
|
||||
cleanup() {
|
||||
log "Cleaning up..."
|
||||
fission env delete --name python || true
|
||||
kubectl delete secret -n default ${fn_secret} || true
|
||||
kubectl delete configmap -n default ${fn_cfgmap} || true
|
||||
rm cfgmap.py || true
|
||||
rm secret.py || true
|
||||
# delete functions
|
||||
for f in ${fn_secret} ${fn_cfgmap} ${fn}
|
||||
do
|
||||
fission fn list | grep ${f} | awk '{print $1;}' | xargs -I@ bash -c "fission function delete --name @"
|
||||
done
|
||||
# delete routes
|
||||
for r in ${fn_secret} ${fn_cfgmap} ${fn}
|
||||
do
|
||||
fission route list | grep ${r} | awk '{print $1;}' | xargs -I@ bash -c "fission route delete --name @"
|
||||
done
|
||||
clean_resource_by_id $TEST_ID
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
@@ -33,11 +28,8 @@ else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
cp secret.py.template secret.py
|
||||
sed -i "s/{{ FN_SECRET }}/${fn_secret}/g" secret.py
|
||||
|
||||
cp cfgmap.py.template cfgmap.py
|
||||
sed -i "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" cfgmap.py
|
||||
sed "s/{{ FN_SECRET }}/${fn_secret}/g" $(dirname $0)/secret.py.template > $tmp_dir/secret.py
|
||||
sed "s/{{ FN_CFGMAP }}/${fn_cfgmap}/g" $(dirname $0)/cfgmap.py.template > $tmp_dir/cfgmap.py
|
||||
|
||||
checkFunctionResponse() {
|
||||
log "Doing an HTTP GET on the function's route"
|
||||
@@ -59,17 +51,14 @@ checkFunctionResponse() {
|
||||
export -f checkFunctionResponse
|
||||
|
||||
# Create a hello world function in nodejs, test it with an http trigger
|
||||
log "Pre-test cleanup"
|
||||
fission env delete --name python || true
|
||||
|
||||
log "Creating python env"
|
||||
fission env create --name python --image fission/python-env
|
||||
fission env create --name $env --image $PYTHON_RUNTIME_IMAGE
|
||||
|
||||
log "Creating secret"
|
||||
kubectl create secret generic ${fn_secret} --from-literal=TEST_KEY="TESTVALUE" -n default
|
||||
|
||||
log "Creating function with secret"
|
||||
fission fn create --name ${fn_secret} --env python --code secret.py --secret ${fn_secret}
|
||||
fission fn create --name ${fn_secret} --env $env --code $tmp_dir/secret.py --secret ${fn_secret}
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_secret} --url /${fn_secret} --method GET
|
||||
@@ -81,7 +70,7 @@ timeout 60 bash -c "checkFunctionResponse ${fn_secret} 'TESTVALUE' 'secret'"
|
||||
|
||||
log "Creating function with newdeploy executorType and new secret value"
|
||||
kubectl patch secrets ${fn_secret} -p '{"data":{"TEST_KEY":"TkVXVkFMCg=="}}' -n default
|
||||
fission fn create --name ${fn_secret}-1 --env python --code secret.py --secret ${fn_secret} --executortype newdeploy
|
||||
fission fn create --name ${fn_secret}-1 --env $env --code $tmp_dir/secret.py --secret ${fn_secret} --executortype newdeploy
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_secret}-1 --url /${fn_secret}-1 --method GET
|
||||
@@ -95,7 +84,7 @@ log "Creating configmap"
|
||||
kubectl create configmap ${fn_cfgmap} --from-literal=TEST_KEY="TESTVALUE" -n default
|
||||
|
||||
log "creating function with configmap"
|
||||
fission fn create --name ${fn_cfgmap} --env python --code cfgmap.py --configmap ${fn_cfgmap}
|
||||
fission fn create --name ${fn_cfgmap} --env $env --code $tmp_dir/cfgmap.py --configmap ${fn_cfgmap}
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_cfgmap} --url /${fn_cfgmap} --method GET
|
||||
@@ -107,7 +96,7 @@ timeout 60 bash -c "checkFunctionResponse ${fn_cfgmap} 'TESTVALUE' 'configmap'"
|
||||
|
||||
log "Creating function with newdeploy executorType and new configmap value"
|
||||
kubectl patch configmap ${fn_cfgmap} -p '{"data":{"TEST_KEY":"NEWVAL"}}' -n default
|
||||
fission fn create --name ${fn_cfgmap}-1 --env python --code cfgmap.py --configmap ${fn_cfgmap} --executortype newdeploy
|
||||
fission fn create --name ${fn_cfgmap}-1 --env $env --code $tmp_dir/cfgmap.py --configmap ${fn_cfgmap} --executortype newdeploy
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn_cfgmap}-1 --url /${fn_cfgmap}-1 --method GET
|
||||
@@ -118,7 +107,7 @@ sleep 5
|
||||
timeout 60 bash -c "checkFunctionResponse ${fn_cfgmap}-1 'NEWVAL' 'configmap'"
|
||||
|
||||
log "testing creating a function without a secret or configmap"
|
||||
fission function create --name ${fn} --env python --code empty.py
|
||||
fission function create --name ${fn} --env $env --code $(dirname $0)/empty.py
|
||||
|
||||
log "Creating route"
|
||||
fission route create --function ${fn} --url /${fn} --method GET
|
||||
@@ -128,3 +117,5 @@ sleep 5
|
||||
|
||||
log "HTTP GET on the function's route"
|
||||
timeout 60 bash -c "checkFunctionResponse ${fn} 'yes' 'configmap'"
|
||||
|
||||
log "Test PASSED"
|
||||
|
||||
Reference in New Issue
Block a user