- 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>
56 lines
1.4 KiB
Bash
56 lines
1.4 KiB
Bash
#!/usr/bin/env bats
|
|
# Unit tests for build script functions
|
|
|
|
# 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"
|
|
|
|
# Create mock directory structure
|
|
mkdir -p "${TEST_TEMP_DIR}/config"
|
|
mkdir -p "${TEST_TEMP_DIR}/output"
|
|
|
|
# Override variables for testing
|
|
PROJECT_ROOT="$TEST_TEMP_DIR"
|
|
CONFIG_DIR="$TEST_TEMP_DIR/config"
|
|
OUTPUT_DIR="$TEST_TEMP_DIR/output"
|
|
|
|
# Test with missing tools (should fail)
|
|
run validate_environment
|
|
assert_failure
|
|
}
|
|
|
|
@test "prepare_build creates output directory" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
# Override variables for testing
|
|
PROJECT_ROOT="$TEST_TEMP_DIR"
|
|
OUTPUT_DIR="$TEST_TEMP_DIR/output"
|
|
|
|
# Remove directory if it exists
|
|
rm -rf "$OUTPUT_DIR"
|
|
|
|
# Run function
|
|
run prepare_build
|
|
assert_success
|
|
|
|
# Check directory was created
|
|
assert [ -d "$OUTPUT_DIR" ]
|
|
}
|
|
|
|
@test "build_iso fails without live-build setup" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
# Override variables for testing
|
|
PROJECT_ROOT="$TEST_TEMP_DIR"
|
|
OUTPUT_DIR="$TEST_TEMP_DIR/output"
|
|
|
|
# Run function
|
|
run build_iso
|
|
assert_failure
|
|
} |