Changeset - 47c1170b0e4d
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2020-01-06 16:08:41
branko@majic.rs
MAR-148: Extend test wrapper script to support running only the linting test.
1 file changed with 35 insertions and 4 deletions:
0 comments (0 inline, 0 general)
scripts/run_tests.sh
Show inline comments
 
@@ -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
 

	
0 comments (0 inline, 0 general)