This project uses BATS (Bash Automated Testing System) for testing shell scripts.
Run all tests:
./run-tests.shRun a specific test:
./run-tests.sh test-run-trivy-scan.bats
# or
./run-tests.sh run-trivy-scanThe run-tests.sh script will automatically install BATS locally if not found. It will:
- Check for system-wide BATS installation
- Check for local BATS in
.bats/directory - Clone and install BATS locally if needed
Via Homebrew (requires admin):
brew install bats-coreManual Clone:
git clone https://github.com/bats-core/bats-core.git .bats/bats-core
cd .bats/bats-core
./install.sh ..Tests are located in tests/shell/:
test-run-trivy-scan.bats- Tests for Trivy scannertest-run-grype-scan.bats- Tests for Grype scannertest-run-trufflehog-scan.bats- Tests for TruffleHog scannertest-run-clamav-scan.bats- Tests for ClamAV scannertest-run-checkov-scan.bats- Tests for Checkov scannertest-run-garak-scan.bats- Tests for Garak scannertest-run-xeol-scan.bats- Tests for Xeol scannertest-run-sonar-analysis.bats- Tests for SonarQube scannertest-run-sbom-scan.bats- Tests for SBOM generationtest-run-helm-build.bats- Tests for Helm buildstest-run-anchore-scan.bats- Tests for Anchore scannertest-run-target-security-scan.bats- Tests for orchestratortest-scan-directory-template.bats- Tests for shared utilities
BATS test syntax:
#!/usr/bin/env bats
@test "description of test" {
# Test commands
run command arg1 arg2
[ "$status" -eq 0 ]
[[ "$output" =~ "expected string" ]]
}Common assertions:
[ "$status" -eq 0 ]- Command succeeded[ "$status" -ne 0 ]- Command failed[[ "$output" =~ "pattern" ]]- Output matches pattern[ -f "file.txt" ]- File exists[ -x "script.sh" ]- File is executable
Tests check for:
- Existence - Script files exist and are executable
- Help Functions - Scripts show help with
--helpor-h - Dependencies - Scripts source required templates
- Functionality - Core features work as expected
Tests can be integrated into CI/CD pipelines:
# GitHub Actions example
- name: Run BATS tests
run: ./run-tests.shBATS not found:
./run-tests.sh
# This will auto-install BATS locallyPermission denied:
chmod +x run-tests.sh
chmod +x scripts/shell/*.shTest failures:
- Check script syntax:
bash -n scripts/shell/script-name.sh - Run script directly:
bash scripts/shell/script-name.sh --help - Check for missing dependencies