Changeset - 0ae6f90ca16a
[Not reviewed]
0 2 0
Branko Majic (branko) - 6 years ago 2017-11-27 20:54:17
branko@majic.rs
MAR-128: Updated script for running tests and documentation:

- Updated script, removing parts related to separate platform testing
from old version of Molecule.
- Updated instructions for running the test script.
2 files changed with 30 insertions and 38 deletions:
0 comments (0 inline, 0 general)
docs/development.rst
Show inline comments
 
@@ -129,18 +129,11 @@ In order to run tests for a specific role, perform the following steps:
 

	
 
     cd roles/ROLENAME/
 

	
 
3. List available supported platforms::
 

	
 
     molecule list
 

	
 
4. Run tests for default platform (Debian Jessie)::
 
3. Run the default test scenario (this will normally test against
 
   multiple Debian versions if supported)::
 

	
 
     molecule test
 

	
 
5. Run tests for Debian Stretch (if role tests support it)::
 

	
 
     molecule test --platform debian-stretch64
 

	
 

	
 
Running role tests via shell script
 
-----------------------------------
scripts/run_tests.sh
Show inline comments
 
@@ -34,16 +34,17 @@ The script iterates over all roles within sub-directory "roles" (relative to
 
working directory) that have a valid Molecule configuration, runs the tests, and
 
optionally writes report for all tested roles (see option -r).
 

	
 
All platforms specified in Molecule configuration are tested.
 
Only the default scenario is tested at the moment.
 

	
 
$program accepts the following options:
 

	
 
    -r
 
        Generate report for all roles under sub-directory of current directory
 
        "test_report-YYYY_MM_DD-hh_mm". Within the sub-directory each role will
 
        have its own file named "role-ROLENAME-PLATFORMNAME.txt". In addition, a
 
        summary file (summary.txt) is produced with overview of which roles have
 
        passed, failed, and which roles were skipped.
 
        Generate report for all roles under sub-directory of current
 
        directory "test_report-YYYY_MM_DD-hh_mm". Within the
 
        sub-directory each role will have its own file named
 
        "role-ROLENAME.txt". In addition, a summary file (summary.txt)
 
        is produced with overview of which roles have passed, failed,
 
        and which roles were skipped.
 

	
 
    -d
 
        Enable debug mode.
 
@@ -201,7 +202,7 @@ for role in "${roles[@]}"; do
 
    if [[ ! -d "roles/$role" ]]; then
 
        warning "Could not locate role $role in directory $role_dir"
 
        roles_to_skip+=("$role")
 
    elif [[ -f "$role_dir/molecule.yml" ]]; then
 
    elif [[ -f "$role_dir/molecule/default/molecule.yml" ]]; then
 
        debug "Role $role contains Molecule configuration."
 
         roles_to_test+=("$role")
 
    else
 
@@ -250,35 +251,33 @@ for role in "${roles_to_test[@]}"; do
 

	
 
    # Run tests.
 
    cd "$role_dir"
 
    for platform in $(molecule status --platforms --porcelain | cut -f 1 -d ' '); do
 

	
 
        if [[ $report == 1 ]]; then
 
            report_file="$report_directory/role-${role}-${platform}.txt"
 
        else
 
            report_file="/dev/null"
 
        fi
 
    if [[ $report == 1 ]]; then
 
        report_file="$report_directory/role-${role}.txt"
 
    else
 
        report_file="/dev/null"
 
    fi
 

	
 
        info "Running tests for: $role ($platform)"
 
        molecule test --destroy always --platform "$platform" 2>&1 | tee "$report_file"
 
    info "Running tests for: $role"
 
    molecule test --destroy always 2>&1 | tee "$report_file"
 

	
 
        # Determine result.
 
        if [[ "${PIPESTATUS[0]}" == 0 ]]; then
 
            passed_roles+=("$role ($platform)")
 
    # Determine result.
 
    if [[ "${PIPESTATUS[0]}" == 0 ]]; then
 
        passed_roles+=("$role")
 

	
 
            # Log failure in summary if requested.
 
            [[ $report == 1 ]] && echo "[PASS] $role ($platform)" >> "$report_summary"
 
        else
 
            test_result=$ERROR_FAILED_ROLES
 
            failed_roles+=("$role ($platform)")
 
        # Log failure in summary if requested.
 
        [[ $report == 1 ]] && echo "[PASS] $role" >> "$report_summary"
 
    else
 
        test_result=$ERROR_FAILED_ROLES
 
        failed_roles+=("$role")
 

	
 
            # Log failure in summary if requested.
 
            [[ $report == 1 ]] && echo "[FAIL] $role ($platform)" >> "$report_summary"
 
        fi
 
        # Log failure in summary if requested.
 
        [[ $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 any error.
 
    molecule destroy
 

	
 
    done
 
done
 

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