diff --git a/examples/flogo/simple/sanity.sh b/examples/flogo/simple/sanity.sh new file mode 100755 index 0000000..b43527e --- /dev/null +++ b/examples/flogo/simple/sanity.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +function get_test_cases { + local my_list=( testcase1 ) + echo "${my_list[@]}" +} + +# This Testcase creates flogo rules binary and checks for name bob +function testcase1 { +pushd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/simple +flogo create -f flogo.json +cp functions.go simplerules/src +cd simplerules +flogo build +./bin/simplerules > /tmp/testcase1.log 2>&1 & +pId=$! + +response=$(curl --request GET localhost:7777/test/n1?name=Bob --write-out '%{http_code}' --silent --output /dev/null) +response1=$(curl --request GET localhost:7777/test/n2?name=Bob --write-out '%{http_code}' --silent --output /dev/null) + +kill -9 $pId +if [ $response -eq 200 ] && [ $response1 -eq 200 ] && [[ "echo $(cat /tmp/testcase1.log)" =~ "Rule fired" ]] + then + echo "PASS" + else + echo "FAIL" +fi +cd .. +rm -rf simplerules +popd +} \ No newline at end of file diff --git a/examples/rulesapp/sanity.sh b/examples/rulesapp/sanity.sh new file mode 100644 index 0000000..aff0c8a --- /dev/null +++ b/examples/rulesapp/sanity.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +function get_test_cases { + local my_list=( testcase1 ) + echo "${my_list[@]}" +} + +# This testcase checks for name bob +function testcase1 { +pushd $GOPATH/src/github.com/project-flogo/rules/examples/rulesapp +rm -rf /tmp/testcase1.log +go run main.go > /tmp/testcase1.log 2>&1 + +if [[ "echo $(cat /tmp/testcase1.log)" =~ "Rule fired" ]] + then + echo "PASS" + else + echo "FAIL" +fi +popd +} \ No newline at end of file diff --git a/scripts/README.md b/scripts/README.md new file mode 100755 index 0000000..6cdeff0 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,37 @@ +## Sanity Testing + +* There is a shell script file `run_sanitytest.sh` that performs sanity testing against rules/examples and generates html report. + +* This script file checks for all available `sanity.sh` files inside rules/examples and run tests against individual `sanity.sh` file + + +* To run sanity tests + +``` +cd $GOPATH/src/github.com/project-flogo/rules/scripts +./run_sanitytest.sh +``` + +* Testcase status of each example is updated in the html report and test report is made available in scripts folder. + + +### Contributing + +If you're adding a new rules example, optionally you can add sanity test file with name `sanity.sh`. Below is the template used for creating test file. + +``` +#!/bin/bash + +function get_test_cases { + local my_list=( testcase1 ) + echo "${my_list[@]}" +} + +function testcase1 { +# Add detailed steps to execute the test case +} +``` +Sample sanity test file can be found at +``` +$GOPATH/src/github.com/project-flogo/rules/examples/flogo/simple/sanity.sh +``` \ No newline at end of file diff --git a/scripts/run_sanitytest.sh b/scripts/run_sanitytest.sh new file mode 100755 index 0000000..f10de76 --- /dev/null +++ b/scripts/run_sanitytest.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +RULESPATH=$GOPATH/src/github.com/project-flogo/rules +export FILENAME="RulesSanityReport.html" +HTML=" +

Rules Sanity Report

Summary

Number of test cases passed
Number of test cases failed
Total test cases
Recipe Testcase Status
" + +echo $HTML >> $RULESPATH/scripts/$FILENAME +PASS_COUNT=0 FAIL_COUNT=0 + +# Fetch list of sanity.sh files in examples folder +function get_sanitylist() +{ + cd $RULESPATH/examples + find | grep sanity.sh > file.txt + readarray -t array < file.txt + for EXAMPLE in "${array[@]}" + do + echo "$EXAMPLE" + RECIPE=$(echo $EXAMPLE | sed -e 's/\/sanity.sh//g' | sed -e 's/\.\///g' | sed -e 's/\//-/g') + execute_testcase + done +} + +# Execute and obtain testcase status (pass/fail) +function execute_testcase() +{ + echo $RECIPE + source $EXAMPLE + TESTCASE_LIST=($(get_test_cases)) + sleep 10 + for ((i=0;i < ${#TESTCASE_LIST[@]};i++)) + do + TESTCASE=$(${TESTCASE_LIST[i]}) + sleep 10 + if [[ $TESTCASE == *"PASS"* ]]; then + echo "$RECIPE":"Passed" + PASS_COUNT=$((PASS_COUNT+1)) + sed -i "s/<\/tr> <\/table>/$RECIPE<\/td>${TESTCASE_LIST[i]}<\/td>PASS<\/td><\/tr><\/tr> <\/table>/g" $RULESPATH/scripts/$FILENAME + else + echo "$RECIPE":"Failed" + FAIL_COUNT=$((FAIL_COUNT+1)) + sed -i "s/<\/tr> <\/table>/$RECIPE<\/td>${TESTCASE_LIST[i]}<\/td>FAIL<\/td><\/tr><\/tr> <\/table>/g" $RULESPATH/scripts/$FILENAME + fi + done +} + +get_sanitylist + +# Update testcase count in html report +sed -i s/"passed <\/td> "/"passed <\/td> $PASS_COUNT"/g $RULESPATH/scripts/$FILENAME +sed -i s/"failed <\/td> "/"failed <\/td> $FAIL_COUNT"/g $RULESPATH/scripts/$FILENAME +sed -i s/"cases<\/td>"/"cases<\/td>$((PASS_COUNT+FAIL_COUNT))"/g $RULESPATH/scripts/$FILENAME \ No newline at end of file