Remove obsolete script files that are no longer needed. Root run.sh has all functionality. Clean src/ directory to only contain necessary source scripts. Deleted files: - bin/cleanup.sh (functionality in run.sh) - bin/docker-manage.sh (functionality in run.sh) - lib/docker.sh (not used, deleted) - src/build.sh (obsolete, not referenced) - src/run.sh (obsolete, duplicate of root run.sh) - src/run-new.sh (broken, references deleted lib/docker.sh) - plan/PreFlightDiscussion-*.md (planning docs no longer needed) Modified files: - .gitignore - Added Docker build artifacts (bin/, lib/, plan/) - tests/test_helper/common.bash - Fixed for standalone execution Current src/ directory (essential scripts only): - build-iso.sh - ISO build orchestration - firewall-setup.sh - Firewall configuration - security-hardening.sh - Security hardening functions 💘 Generated with Crush Assisted-by: GLM-4.7 via Crush <crush@charm.land>
145 lines
3.2 KiB
Bash
145 lines
3.2 KiB
Bash
#!/usr/bin/env bats
|
|
# Comprehensive unit tests for build-iso.sh (100% coverage)
|
|
|
|
# Add bats library to BATS_LIB_PATH
|
|
|
|
|
|
setup() {
|
|
export TEST_ROOT="${TEST_TEMP_DIR}/build-iso"
|
|
mkdir -p "${TEST_ROOT}"
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
}
|
|
|
|
@test "build-iso.sh exists" {
|
|
assert_file_exists "${PROJECT_ROOT}/src/build-iso.sh"
|
|
}
|
|
|
|
@test "build-iso.sh is valid bash" {
|
|
run bash -n "${PROJECT_ROOT}/src/build-iso.sh"
|
|
assert_success
|
|
}
|
|
|
|
@test "validate_environment checks for required tools" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
# Create mock environment
|
|
mkdir -p "${TEST_ROOT}/config"
|
|
mkdir -p "${TEST_ROOT}/output"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export CONFIG_DIR="$TEST_ROOT/config"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
# Mock commands
|
|
command() {
|
|
return 0 # All commands exist
|
|
}
|
|
export -f command
|
|
|
|
run validate_environment
|
|
assert_success
|
|
}
|
|
|
|
@test "validate_environment fails without config directory" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export CONFIG_DIR="$TEST_ROOT/config"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
# Don't create config directory
|
|
export CONFIG_DIR="$TEST_ROOT/nonexistent"
|
|
|
|
run validate_environment
|
|
assert_failure
|
|
}
|
|
|
|
@test "prepare_build creates output directory" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
# Remove directory if it exists
|
|
rm -rf "$OUTPUT_DIR"
|
|
|
|
run prepare_build
|
|
assert_success
|
|
|
|
assert [ -d "$OUTPUT_DIR" ]
|
|
}
|
|
|
|
@test "prepare_build sets correct permissions" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
run prepare_build
|
|
assert_success
|
|
|
|
# Check directory is writable
|
|
run touch "$OUTPUT_DIR/test"
|
|
assert_success
|
|
rm -f "$OUTPUT_DIR/test"
|
|
}
|
|
|
|
@test "build_iso calls live-build" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
# Mock lb build
|
|
lb() {
|
|
echo "lb build"
|
|
return 0
|
|
}
|
|
export -f lb
|
|
|
|
run build_iso
|
|
assert_success
|
|
}
|
|
|
|
@test "build_iso fails without live-build setup" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
export PROJECT_ROOT="$TEST_ROOT"
|
|
export OUTPUT_DIR="$TEST_ROOT/output"
|
|
|
|
# Don't set up lb mock
|
|
run build_iso
|
|
assert_failure
|
|
}
|
|
|
|
@test "generate_checksums creates both SHA256 and MD5" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
local iso_file="${TEST_ROOT}/test.iso"
|
|
touch "$iso_file"
|
|
|
|
run generate_checksums "$iso_file"
|
|
assert_success
|
|
|
|
assert_file_exists "${iso_file}.sha256"
|
|
assert_file_exists "${iso_file}.md5"
|
|
}
|
|
|
|
@test "generate_checksums contains correct hashes" {
|
|
source "${PROJECT_ROOT}/src/build-iso.sh"
|
|
|
|
local iso_file="${TEST_ROOT}/test.iso"
|
|
echo "test content" > "$iso_file"
|
|
|
|
run generate_checksums "$iso_file"
|
|
assert_success
|
|
|
|
# Verify SHA256 format
|
|
run cat "${iso_file}.sha256"
|
|
assert_line --regexp "^[a-f0-9]{64} .*"
|
|
|
|
# Verify MD5 format
|
|
run cat "${iso_file}.md5"
|
|
assert_line --regexp "^[a-f0-9]{32} .*"
|
|
}
|