diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh index 22ad07887587a500e5ee11b0e9591f3d6764d398..0c1c3b5df6de1fdd0344f98a3038711f0ca9543f 100755 --- a/scripts/run_tests.sh +++ b/scripts/run_tests.sh @@ -46,6 +46,18 @@ $program accepts the following options: is produced with overview of which roles have passed, failed, and which roles were skipped. + -l all|lint + Limit what type of tests should be run. Currently supported + values are: + + all + Runs all the available tests. This is the default. + + lint + Runs only the linting tests. This is useful for performing + a quick check on syntax prior to running more extensive + testing. + -d Enable debug mode. -v @@ -139,6 +151,7 @@ debug=0 # Default values. report=0 +tests=all # If no arguments were given, just show usage help. if [[ -z $1 ]]; then @@ -147,9 +160,10 @@ if [[ -z $1 ]]; then fi # Parse the arguments -while getopts "rqdvh" opt; do +while getopts "rl:qdvh" opt; do case "$opt" in r) report=1;; + l) tests="$OPTARG";; d) debug=1;; v) version exit "$SUCCESS";; @@ -171,6 +185,12 @@ fi # Assume success. test_result=0 +# Verify arguments. +if [[ $tests != "all" && $tests != "lint" ]]; then + error "Unsupported type of tests requested: $tests" + exit $ERROR_ARGUMENTS +fi + # Assemble list of roles to run against. roles=() roles_to_test=() @@ -196,6 +216,11 @@ else done fi +if [[ ${#roles[@]} == 0 ]]; then + error "No role has been specified for testing." + exit $ERROR_ARGUMENTS +fi + # Determine which roles have available tests. for role in "${roles[@]}"; do role_dir="roles/$role" @@ -259,7 +284,11 @@ for role in "${roles_to_test[@]}"; do fi info "Running tests for: $role" - molecule test --destroy always 2>&1 | tee "$report_file" + if [[ $tests == all ]]; then + molecule test --destroy always 2>&1 | tee "$report_file" + elif [[ $tests == lint ]]; then + molecule lint 2>&1 | tee "$report_file" + fi # Determine result. if [[ "${PIPESTATUS[0]}" == 0 ]]; then @@ -275,8 +304,10 @@ for role in "${roles_to_test[@]}"; do [[ $report == 1 ]] && echo "[FAIL] $role" >> "$report_summary" fi - # Make sure the instances have been cleaned-up to avoid any error. - molecule destroy + # Make sure the instances have been cleaned-up to avoid errors. + if [[ $tests == all ]]; then + molecule destroy + fi done