Test framework improvement (#1128)
This commit is contained in:
committed by
Ta-Ching Chen
parent
1e8dfa38da
commit
c3177f9ebd
@@ -2,27 +2,35 @@
|
||||
|
||||
#
|
||||
# Create a function and trigger it using NATS
|
||||
# To run this on Minikube, uncomment line 18
|
||||
# To run this on Minikube, uncomment line 24
|
||||
|
||||
set -euo pipefail
|
||||
set +x
|
||||
source $(dirname $0)/../../../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
DIR=$(dirname $0)
|
||||
|
||||
clusterID="fissionMQTrigger"
|
||||
topic="foo.bar"
|
||||
resptopic="foo.foo"
|
||||
errortopic="foo.error"
|
||||
pubClientID="clientPub-$TEST_ID"
|
||||
subClientID="clientSub-$TEST_ID"
|
||||
topic="foo.bar$TEST_ID"
|
||||
resptopic="foo.foo$TEST_ID"
|
||||
errortopic="foo.error$TEST_ID"
|
||||
maxretries=1
|
||||
# FISSION_NATS_STREAMING_URL="http://defaultFissionAuthToken@$(minikube ip):4222"
|
||||
expectedRespOutput="[foo.error]: 'Hello, World!'"
|
||||
expectedRespOutput="[foo.error$TEST_ID]: 'Hello, World!'"
|
||||
|
||||
env=nodejs-$TEST_ID
|
||||
fn=hello-$TEST_ID
|
||||
mqt=mqt-$TEST_ID
|
||||
|
||||
cleanup() {
|
||||
log "Cleaning up..."
|
||||
fission env delete --name nodejs || true
|
||||
fission fn delete --name $fn || true
|
||||
fission mqtrigger delete --name $mqt || true
|
||||
clean_resource_by_id $TEST_ID
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
@@ -31,18 +39,13 @@ else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
log "Pre-test cleanup"
|
||||
fission env delete --name nodejs || true
|
||||
|
||||
log "Creating nodejs env"
|
||||
fission env create --name nodejs --image fission/node-env
|
||||
fission env create --name $env --image $NODE_RUNTIME_IMAGE
|
||||
|
||||
log "Creating function"
|
||||
fn=hello-$(date +%s)
|
||||
fission fn create --name $fn --env nodejs --code $DIR/main_error.js --method GET
|
||||
fission fn create --name $fn --env $env --code $DIR/main_error.js --method GET
|
||||
|
||||
log "Creating message queue trigger"
|
||||
mqt=mqt-$(date +%s)
|
||||
fission mqtrigger create --name $mqt --function $fn --mqtype "nats-streaming" --topic $topic --resptopic $resptopic --errortopic $errortopic --maxretries $maxretries
|
||||
log "Updated mqtrigger list"
|
||||
fission mqtrigger list
|
||||
@@ -54,28 +57,20 @@ sleep 5
|
||||
# Send a message
|
||||
#
|
||||
log "Sending message"
|
||||
go run $DIR/stan-pub.go -s $FISSION_NATS_STREAMING_URL -c $clusterID -id clientPub $topic ""
|
||||
go run $DIR/stan-pub.go -s $FISSION_NATS_STREAMING_URL -c $clusterID -id $pubClientID $topic ""
|
||||
|
||||
#
|
||||
# Wait for message on error topic
|
||||
#
|
||||
log "Waiting for response"
|
||||
TIMEOUT=timeout
|
||||
if [ $(uname -s) == 'Darwin' ]
|
||||
then
|
||||
# If this fails on mac os, do "brew install coreutils".
|
||||
TIMEOUT=gtimeout
|
||||
fi
|
||||
response=$(go run $DIR/stan-sub.go --last -s $FISSION_NATS_STREAMING_URL -c $clusterID -id clientSub $errortopic 2>&1)
|
||||
response=$(go run $DIR/stan-sub.go --last -s $FISSION_NATS_STREAMING_URL -c $clusterID -id $subClientID $errortopic 2>&1)
|
||||
|
||||
log "Subscriber received response: $response"
|
||||
|
||||
fission mqtrigger delete --name $mqt
|
||||
# kubectl delete functions --all
|
||||
|
||||
if [[ "$response" != "$expectedRespOutput" ]]; then
|
||||
log "$response is not equal to $expectedRespOutput"
|
||||
log "'$response' is not equal to '$expectedRespOutput'"
|
||||
exit 1
|
||||
else
|
||||
log "Responses match."
|
||||
fi
|
||||
log "Test PASSED"
|
||||
|
||||
Reference in New Issue
Block a user