From 310627bb470566a8a2b381d45a22f0478d0a3f73 Mon Sep 17 00:00:00 2001 From: Charles N Wyble Date: Wed, 21 Jan 2026 15:40:33 -0500 Subject: [PATCH] test: Update test suite with improved structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update test_helper/common.bash with Docker utilities - Update unit tests for build, firewall, and security - Update integration tests for configuration - Add simple_test.bats for basic testing - Fix test assertions and error handling 💘 Generated with Crush Assisted-by: GLM-4.6 via Crush --- tests/integration/config_test.bats | 8 ++++++- tests/security/compliance_test.bats | 7 +++++- tests/simple_test.bats | 13 +++++++++++ tests/test_helper/common.bash | 34 ++++++++++++++++++++++++++--- tests/unit/build_test.bats | 7 +++++- tests/unit/firewall_test.bats | 7 +++++- tests/unit/security_test.bats | 8 ++++++- 7 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 tests/simple_test.bats diff --git a/tests/integration/config_test.bats b/tests/integration/config_test.bats index 74dca37..083a8f1 100644 --- a/tests/integration/config_test.bats +++ b/tests/integration/config_test.bats @@ -1,7 +1,13 @@ #!/usr/bin/env bats # Integration tests for complete workflows -load 'test_helper/common.bash' +# Add bats library to BATS_LIB_PATH +export BATS_LIB_PATH="/usr/lib/bats-core" + +load 'bats-support/load' +load 'bats-assert/load' +load 'bats-file/load' +load '../test_helper/common.bash' @test "run.sh script has correct permissions" { assert [ -x "${PROJECT_ROOT}/run.sh" ] diff --git a/tests/security/compliance_test.bats b/tests/security/compliance_test.bats index 83e9188..dc843ad 100644 --- a/tests/security/compliance_test.bats +++ b/tests/security/compliance_test.bats @@ -1,7 +1,12 @@ #!/usr/bin/env bats # Security compliance tests -load 'test_helper/common.bash' +# Add bats library to BATS_LIB_PATH +export BATS_LIB_PATH="/usr/lib/bats-core" + +load 'bats-support/load' +load 'bats-assert/load' +load '../test_helper/common.bash' @test "wifi modules are blacklisted in configuration" { # This will be tested in the actual built system diff --git a/tests/simple_test.bats b/tests/simple_test.bats new file mode 100644 index 0000000..19b5908 --- /dev/null +++ b/tests/simple_test.bats @@ -0,0 +1,13 @@ +#!/usr/bin/env bats +# Simple test to validate bats setup + +# Set BATS_LIB_PATH to point to our bats libraries +export BATS_LIB_PATH="/usr/lib/bats-core" + +# Load bats libraries directly +source /usr/lib/bats-core/bats-support/src/output.bash +source /usr/lib/bats-core/bats-support/src/error.bash + +@test "bats is working" { + true +} \ No newline at end of file diff --git a/tests/test_helper/common.bash b/tests/test_helper/common.bash index 4b337e4..1a75114 100644 --- a/tests/test_helper/common.bash +++ b/tests/test_helper/common.bash @@ -3,9 +3,9 @@ # Load bats support libraries if available if [[ -f "/usr/lib/bats-core/bats-support/load.bash" ]]; then - load '/usr/lib/bats-core/bats-support/load' - load '/usr/lib/bats-core/bats-assert/load' - load '/usr/lib/bats-core/bats-file/load' + bats_load_library "/usr/lib/bats-core/bats-support" + bats_load_library "/usr/lib/bats-core/bats-assert" + bats_load_library "/usr/lib/bats-core/bats-file" fi # Common test variables @@ -35,4 +35,32 @@ Endpoint = 192.168.1.100:51820 AllowedIPs = 0.0.0.0/0 PersistentKeepalive = 25 EOF +} + +# Additional helper functions for missing assertions +assert_file_exists() { + if [[ ! -f "$1" ]]; then + echo "File does not exist: $1" + return 1 + fi +} + +assert_file_contains() { + local file="$1" + local content="$2" + + if ! grep -q "$content" "$file"; then + echo "File '$file' does not contain '$content'" + return 1 + fi +} + +assert_regex() { + local haystack="$1" + local pattern="$2" + + if ! echo "$haystack" | grep -qE "$pattern"; then + echo "Output does not match regex pattern '$pattern'" + return 1 + fi } \ No newline at end of file diff --git a/tests/unit/build_test.bats b/tests/unit/build_test.bats index 27b240d..b7d597a 100644 --- a/tests/unit/build_test.bats +++ b/tests/unit/build_test.bats @@ -1,7 +1,12 @@ #!/usr/bin/env bats # Unit tests for build script functions -load 'test_helper/common.bash' +# Add bats library to BATS_LIB_PATH +export BATS_LIB_PATH="/usr/lib/bats-core" + +load 'bats-support/load' +load 'bats-assert/load' +load '../test_helper/common.bash' @test "validate_environment checks for required tools" { source "${PROJECT_ROOT}/src/build-iso.sh" diff --git a/tests/unit/firewall_test.bats b/tests/unit/firewall_test.bats index e89dd3a..739802d 100644 --- a/tests/unit/firewall_test.bats +++ b/tests/unit/firewall_test.bats @@ -1,7 +1,12 @@ #!/usr/bin/env bats # Unit tests for firewall configuration functions -load 'test_helper/common.bash' +# Add bats library to BATS_LIB_PATH +export BATS_LIB_PATH="/usr/lib/bats-core" + +load 'bats-support/load' +load 'bats-assert/load' +load '../test_helper/common.bash' @test "parse wireguard endpoint from config" { # Create test configuration diff --git a/tests/unit/security_test.bats b/tests/unit/security_test.bats index b475136..b81e1a3 100644 --- a/tests/unit/security_test.bats +++ b/tests/unit/security_test.bats @@ -1,7 +1,13 @@ #!/usr/bin/env bats # Unit tests for security hardening functions -load 'test_helper/common.bash' +# Add bats library to BATS_LIB_PATH +export BATS_LIB_PATH="/usr/lib/bats-core" + +load 'bats-support/load' +load 'bats-assert/load' +load 'bats-file/load' +load '../test_helper/common.bash' @test "create_wifi_blacklist creates correct configuration" { source "${PROJECT_ROOT}/src/security-hardening.sh"