Files
shell/docs/testing-fixes.md
Peter Wood 9a941d1752 Enhance setup and testing scripts for improved package management and logging
- Updated setup.sh to check for Nala installation and provide alternative installation methods based on Ubuntu version.
- Added error handling for package installation, allowing fallback to apt if Nala fails.
- Introduced startup.sh to perform container startup checks, including system info and permissions for logs directory.
- Created test-setup.sh to validate bootstrap and setup scripts, including detailed logging of package availability and installation results.
- Implemented checks for missing packages and provided recommendations for manual installation.
- Enhanced logging for better traceability of actions and errors during setup and testing processes.
2025-05-12 13:59:15 -04:00

2.6 KiB

Docker-based Testing Framework Improvements

This document outlines the improvements made to the Docker-based testing framework for validating shell scripts and dotfiles across different environments.

Issues Fixed

1. local Keyword Usage Outside Function

Fixed a syntax error where the local keyword was used outside of a function context:

# Before (incorrect):
for pkg in $packages; do
    local actual_pkg=$(get_package_name "$pkg")
    # ...
done

# After (correct):
for pkg in $packages; do
    actual_pkg=$(get_package_name "$pkg")
    # ...
done

2. Log Directory Handling

Enhanced log directory handling to ensure proper permissions and fallback mechanisms:

  • Added better error handling for log directory creation and permissions
  • Added validation to verify write permissions before proceeding
  • Implemented fallback to /tmp if host volume mounting fails
  • Added debugging information when log operations fail

3. Package Verification

Improved package detection, especially for packages like cowsay and lolcat that are typically installed in /usr/games/:

  • Enhanced test_package() function to check in common alternate locations
  • Added specific handling for packages that may be installed with different paths
  • Added detailed debugging output for problematic packages

4. Docker Container Configuration

Improved the Docker container configuration for more reliable testing:

  • Added proper volume mounting with explicit read/write permissions
  • Added timestamp consistency between host and container
  • Added container type labels to log files for better tracking
  • Enhanced error detection for volume mounting issues

Implementation Details

1. Enhanced Logging System

  • Timestamps are now synchronized between host and container
  • Log file names include container type (ubuntu/debian) for clarity
  • Added validation to confirm logs are properly saved to host

2. Container Environment Setup

  • Improved startup.sh with better diagnostics before running tests
  • Added permissions verification for mounted volumes
  • Added write tests to confirm permissions are correctly set

3. Test Framework Improvements

  • Improved error handling for better diagnostics
  • Enhanced reporting for package detection issues
  • Better isolation between test iterations

Running Tests

To run tests with the improved framework:

# Test in Ubuntu container
./run-docker-tests.sh ubuntu

# Test in Debian container
./run-docker-tests.sh debian

The logs will be saved in the ./logs directory with filenames that include the timestamp and container type.