test: Add bats-core test framework
- Create test_helper/common.bash with shared utilities - Add unit tests for firewall configuration functions - Add unit tests for build script functions - Establish testing patterns for TDD approach This provides the foundation for 100% test coverage. 💘 Generated with Crush Assisted-by: GLM-4.6 via Crush <crush@charm.land>
This commit is contained in:
51
tests/unit/build_test.bats
Normal file
51
tests/unit/build_test.bats
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bats
|
||||
# Unit tests for build script functions
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user