Changeset - da53a3aa5208
[Not reviewed]
0 1 0
Branko Majic (branko) - 17 days ago 2024-09-09 23:01:48
branko@majic.rs
MAR-218: Fix the test run logic in test runner script:

- Linter tests should _always_ be run.
- Test report files should be appended to when using tee.
- Get rid of excess molecule destroy (probably not required any
longer). This will reduce the output and speed up things a little
bit.
1 file changed with 25 insertions and 22 deletions:
0 comments (0 inline, 0 general)
scripts/run_tests.sh
Show inline comments
 
@@ -274,9 +274,6 @@ for role in "${roles_to_test[@]}"; do
 
    # Calculate directories between which we need to move.
 
    role_dir="$work_dir/roles/$role"
 

	
 
    # Run tests.
 
    cd "$role_dir"
 

	
 
    if [[ $report == 1 ]]; then
 
        report_file="$report_directory/role-${role}.txt"
 
    else
 
@@ -284,34 +281,45 @@ for role in "${roles_to_test[@]}"; do
 
    fi
 

	
 
    info "Running tests for: $role"
 
    molecule_result=0
 
    if [[ $tests == all ]]; then
 

	
 
        molecule test --destroy always 2>&1 | tee "$report_file"
 
        last_pipe_status="${PIPESTATUS[0]}"
 
        [[ $last_pipe_status == 0 ]] || molecule_result="$last_pipe_status"
 
    role_test_result=0
 

	
 
    # Switch directory, make sure it is successful.
 
    # shellcheck disable=SC2164  # failed directory switch is dealt with additional checks below.
 
    cd "$role_dir" 2>&1 | tee -a "$report_file"
 
    last_pipe_status="${PIPESTATUS[0]}"
 
    [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status"
 

	
 
    elif [[ $tests == lint ]]; then
 
    # Run the linters.
 
    if [[ $role_test_result == 0 ]]; then
 

	
 
        flake8 . 2>&1 | tee -a "$report_file"
 
        last_pipe_status="${PIPESTATUS[0]}"
 
        [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status"
 

	
 
        flake8 . 2>&1 | tee "$report_file"
 
        yamllint . 2>&1 | tee -a "$report_file"
 
        last_pipe_status="${PIPESTATUS[0]}"
 
        [[ $last_pipe_status == 0 ]] || molecule_result="$last_pipe_status"
 
        [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status"
 

	
 
        yamllint . 2>&1 | tee "$report_file"
 
        ansible-lint -q . 2>&1 | tee -a "$report_file"
 
        last_pipe_status="${PIPESTATUS[0]}"
 
        [[ $last_pipe_status == 0 ]] || molecule_result="$last_pipe_status"
 
        [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status"
 
    fi
 

	
 
    # Run the unit/functional tests (if requested).
 
    if [[ $role_test_result == 0 && $tests == all ]]; then
 

	
 
        ansible-lint --quiet . 2>&1 | tee "$report_file"
 
        molecule test --destroy always 2>&1 | tee -a "$report_file"
 
        last_pipe_status="${PIPESTATUS[0]}"
 
        [[ $last_pipe_status == 0 ]] || molecule_result="$last_pipe_status"
 
        [[ $last_pipe_status == 0 ]] || role_test_result="$last_pipe_status"
 

	
 
    fi
 

	
 
    # Determine result.
 
    if [[ $molecule_result == 0 ]]; then
 
    if [[ $role_test_result == 0 ]]; then
 
        passed_roles+=("$role")
 

	
 
        # Log failure in summary if requested.
 
        # Log success in summary if requested.
 
        [[ $report == 1 ]] && echo "[PASS] $role" >> "$report_summary"
 
    else
 
        test_result=$ERROR_FAILED_ROLES
 
@@ -321,11 +329,6 @@ 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 errors.
 
    if [[ $tests == all ]]; then
 
        molecule destroy
 
    fi
 

	
 
done
 

	
 
for role in "${roles_to_skip[@]}"; do
0 comments (0 inline, 0 general)