Last active
August 13, 2019 09:43
-
-
Save kasunbg/9da2de2d38e49e004a865b3158baea4c to your computer and use it in GitHub Desktop.
Testgrid test.sh template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -euxo pipefail # This provide better error handling for shell scripts | |
HOME=`pwd` | |
TEST_SCRIPT=test.sh | |
function usage() | |
{ | |
echo " | |
Usage bash test.sh --input-dir /workspace/data-bucket/in --output-dir /workspace/data-bucket/out | |
Following are the expected input parameters. all of these are optional | |
--input-dir | -i : input directory for test.sh | |
--output-dir | -o : output directory for test.sh | |
" | |
} | |
#=============== Process Input Arguments =========================================== | |
# ex. command: bash test.sh --input-dir <path-to-input-dir> --output-dir <path-to-output-dir> | |
optspec=":hiom-:" | |
while getopts "$optspec" optchar; do | |
case "${optchar}" in | |
-) | |
case "${OPTARG}" in | |
input-dir) | |
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) | |
INPUT_DIR=$val | |
;; | |
output-dir) | |
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) | |
OUTPUT_DIR=$val | |
;; | |
mvn-opts) | |
val="${!OPTIND}"; OPTIND=$(( $OPTIND + 1 )) | |
MAVEN_OPTS=$val | |
;; | |
*) | |
usage | |
if [ "$OPTERR" = 1 ] && [ "${optspec:0:1}" != ":" ]; then | |
echo "Unknown option --${OPTARG}" >&2 | |
fi | |
;; | |
esac;; | |
h) | |
usage | |
exit 2 | |
;; | |
o) | |
OUTPUT_DIR=$val | |
;; | |
m) | |
MVN_OPTS=$val | |
;; | |
i) | |
INPUT_DIR=$val | |
;; | |
*) | |
usage | |
if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then | |
echo "Non-option argument: '-${OPTARG}'" >&2 | |
fi | |
;; | |
esac | |
done | |
echo "Working directory : ${HOME}" | |
echo "Input files are in directory : ${INPUT_DIR}" | |
echo "Output files need to go to directory : ${OUTPUT_DIR}" | |
export DATA_BUCKET_LOCATION=${INPUT_DIR} | |
#=============== Execute Scenario Tests ========================================== | |
# YOUR TEST EXECUTION LOGIC GOES HERE | |
# A sample execution for maven-based testng/junit tests is shown below. | |
# For maven, we add -fae (fail-at-end), and a system property to reduce jar download log verbosity. | |
mvn clean install -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \ | |
-fae -B -f ./pom.xml | |
#=============== Archive Test Artifacts =========================================== | |
# You need to run following code snippet such that Testgrid can identify the 'test scenarios' | |
# SUREFIRE/JMETER REPORTS MUST NEED TO BE COPIED TO THE $OUTPUT_DIR. | |
echo "Copying surefire-reports to ${OUTPUT_DIR}" | |
mkdir -p ${OUTPUT_DIR} | |
find ./* -name "surefire-reports" -exec cp --parents -r {} ${OUTPUT_DIR} \; | |
#=============== End ============================================================== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment