The LnOS installer includes a comprehensive test suite to ensure reliability and compatibility across different configurations. The testing framework uses multiple approaches to validate the installer functionality, from unit tests to full end-to-end system testing.
The testing suite consists of four main components:
- Shellcheck: Validates shell script syntax and best practices
- Syntax Check: Ensures bash script parsing works correctly
- Location:
scripts/run-tests.sh
- Framework: BATS (Bash Automated Testing System)
- File:
test/unit-tests.batsis run fromscripts/run-test.sh --unit-only - Coverage: Tests individual functions in isolation
- Test Helpers: Uses bats-support, bats-assert, and bats-file for enhanced testing capabilities
There are other testing tools but they're in development, current the two above are the recommended workflow so that we don't need to check w/ a vm all the time to make sure the script will install.
# Static analysis
sudo pacman -S shellcheck
# Unit testing
git clone https://github.com/bats-core/bats-core && cd bats-core && sudo ./install.sh /usr/local
# Integration testing
sudo pacman -S docker
# E2E testing
sudo pacman -S qemu-desktop expectThe unit tests automatically install these helpers if not present:
- bats-support - Enhanced test assertions
- bats-assert - Assertion helpers
- bats-file - File system test utilities
# Run only static analysis
./scripts/run-tests.sh # Static analysis only
./scripts/run-tests.sh --static-only./scripts/run-tests.sh --unit-onlybats test/unit-tests.batsShell linter, prevents common syntax errors
The unit tests cover these installer components:
🔍 Input Validation
- Username validation (format and constraints)
- Password validation (matching, strength)
- Timezone validation (valid timezone detection)
- Disk selection validation
📁 Configuration Management
- Configuration file generation
- Password sanitization in logs
- Configuration persistence and loading
💾 System Detection
- Boot mode detection (UEFI vs BIOS)
- Disk partition naming (NVMe vs SATA)
- Filesystem type validation
🛠️ Component Selection
- Desktop environment selection
- Bootloader selection (GRUB vs systemd-boot)
- Package profile selection
- AUR helper configuration
Docker-based tests validate:
💽 Disk Operations
- Partition table creation
- Loop device handling
- Filesystem formatting (ext4, btrfs)
🔐 Encryption Setup
- LUKS2 encryption container creation
- Encrypted device mapping
- Password-based unlocking
🌐 Network Detection
- Internet connectivity validation
- Package mirror accessibility
📊 Configuration Persistence
- Config file creation and validation
- Sensitive data sanitization
Virtual machine testing includes:
🖥️ Full Installation Flow
- Automated installer execution
- Interactive prompt handling
- Complete system installation
🔄 Boot Testing
- Post-installation boot verification
- System startup validation
- Installed system accessibility
- ✓ Passed: Test completed successfully
- ✗ Failed: Test encountered an error
- ⊝ Skipped: Test was skipped (missing dependencies)
When adding new installer functionality:
- Add unit tests in
test/unit-tests.bats - Mock external dependencies in
test/test_helper/mock_functions.sh - Add integration tests if testing system operations
- Update this documentation for new test categories
@test "component: specific behavior description" {
# Setup test environment
setup_test_vars
# Execute function under test
run function_name
# Assert expected results
assert_success
assert_equal "$variable" "expected_value"
}For unit testing, external commands are mocked:
# Mock interactive input
function gum_input() { echo "mocked_response"; }
export -f gum_input
# Mock system commands
function curl() { return 0; }
export -f curlThe test suite is designed for automated execution in CI/CD environments:
GitHub Actions Ready - Configurations available for:
- Static analysis pipeline
- Unit test execution
- Integration test validation
Development Tools
- Packer templates for automated VM testing
- Vagrant setup for development testing
- Docker containers for isolated testing
BATS Not Found
# Install BATS testing framework
git clone https://github.com/bats-core/bats-core.git
cd bats-core && sudo ./install.sh /usr/localDocker Permission Denied
# Add user to docker group
sudo usermod -aG docker $USER
# Logout and login againQEMU Not Available
# Install QEMU for E2E testing
sudo pacman -S qemu-desktopSlow E2E Tests
- E2E tests require 30+ minutes for full completion
- Use
--quickflag for faster development testing - Run E2E tests only before releases
# Clean up test containers
docker system prune -f
# Remove test virtual machines
rm -f lnos-test-vm.qcow2
# Clean test temporary files
rm -rf /tmp/lnos-test-*- Run quick test suite:
./scripts/run-tests.sh --quick - Verify new functionality has corresponding tests
- Check test coverage report for gaps
- Run full test suite for major changes
- Write failing tests first
- Implement minimum code to pass tests
- Refactor while maintaining test coverage
- Update documentation for new features
For more information about contributing to LnOS development, see our Development Guide.