test: Update test suite with improved structure
- 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 <crush@charm.land>
This commit is contained in:
@@ -1,7 +1,13 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# Integration tests for complete workflows
|
# 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" {
|
@test "run.sh script has correct permissions" {
|
||||||
assert [ -x "${PROJECT_ROOT}/run.sh" ]
|
assert [ -x "${PROJECT_ROOT}/run.sh" ]
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# Security compliance tests
|
# 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" {
|
@test "wifi modules are blacklisted in configuration" {
|
||||||
# This will be tested in the actual built system
|
# This will be tested in the actual built system
|
||||||
|
|||||||
13
tests/simple_test.bats
Normal file
13
tests/simple_test.bats
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
# Load bats support libraries if available
|
# Load bats support libraries if available
|
||||||
if [[ -f "/usr/lib/bats-core/bats-support/load.bash" ]]; then
|
if [[ -f "/usr/lib/bats-core/bats-support/load.bash" ]]; then
|
||||||
load '/usr/lib/bats-core/bats-support/load'
|
bats_load_library "/usr/lib/bats-core/bats-support"
|
||||||
load '/usr/lib/bats-core/bats-assert/load'
|
bats_load_library "/usr/lib/bats-core/bats-assert"
|
||||||
load '/usr/lib/bats-core/bats-file/load'
|
bats_load_library "/usr/lib/bats-core/bats-file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Common test variables
|
# Common test variables
|
||||||
@@ -35,4 +35,32 @@ Endpoint = 192.168.1.100:51820
|
|||||||
AllowedIPs = 0.0.0.0/0
|
AllowedIPs = 0.0.0.0/0
|
||||||
PersistentKeepalive = 25
|
PersistentKeepalive = 25
|
||||||
EOF
|
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
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# Unit tests for build script functions
|
# 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" {
|
@test "validate_environment checks for required tools" {
|
||||||
source "${PROJECT_ROOT}/src/build-iso.sh"
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# Unit tests for firewall configuration functions
|
# 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" {
|
@test "parse wireguard endpoint from config" {
|
||||||
# Create test configuration
|
# Create test configuration
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
# Unit tests for security hardening functions
|
# 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" {
|
@test "create_wifi_blacklist creates correct configuration" {
|
||||||
source "${PROJECT_ROOT}/src/security-hardening.sh"
|
source "${PROJECT_ROOT}/src/security-hardening.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user