Overview
The dotfiles repository includes a comprehensive test suite to verify that packages are installed correctly, dotfiles are applied, and encryption keys are properly configured. Tests are written in Bash and can be run locally or in CI.Test Suite Structure
The test suite consists of three main test scripts:1. Package Installation Tests (test-packages.sh)
Verifies that all required packages and commands are available on the system.
Location: tests/test-packages.sh
What it checks:
- APT packages via
dpkg -l - Snap packages via
snap list - Command availability via
command -v
SKIP_GUI_TESTS environment variable:
2. Dotfiles Application Tests (test-dotfiles.sh)
Verifies that chezmoi successfully applied dotfiles to the home directory.
Location: tests/test-dotfiles.sh
What it checks:
TEST_HOME environment variable to test a different user’s home directory (useful for CI).
3. Age Key Setup Tests (test-age-key.sh)
Verifies that the age encryption key was correctly retrieved from Bitwarden or generated.
Location: tests/test-age-key.sh
What it checks:
- Key file exists at
~/.config/chezmoi/key.txt - File permissions are
600 - Key format is valid (starts with
AGE-SECRET-KEY-or contains# public key:) - Key was retrieved from Bitwarden fixture (in CI)
Running Tests Locally
Run All Tests
Execute the test runner script to run all three test suites:Run Individual Tests
You can run individual test scripts:Skip GUI Tests
When running in headless environments (like CI containers), skip GUI-related tests:Test a Different User
Use theTEST_HOME environment variable to test dotfiles in a different home directory:
Mock Bitwarden CLI for Testing
The repository includes a mock Bitwarden CLI for testing without requiring a real Bitwarden account. Location:tests/mocks/bw
How It Works
The mock reads from a JSON fixture file instead of connecting to Bitwarden:Using the Mock in CI
The CI pipeline installs the mock globally and points it to the fixture:Fixture Data Structure
The fixture file (tests/fixtures/bw-data.json) contains a fake Bitwarden vault:
Test Runner Implementation
Therun-all.sh script (tests/run-all.sh:1) orchestrates all tests:
Adding New Tests
When adding new packages or configuration:-
For new packages: Update
tests/test-packages.shwith appropriate checks: -
For new dotfiles: Update
tests/test-dotfiles.shwith file checks: - For new encrypted files: Ensure the age key test passes
Always update tests when modifying
ansible/group_vars/all.yml to maintain test coverage.