feat(bash): startup-scripts reworked + bash scripts workflow integration (#22401)

This commit is contained in:
Yehonal
2025-07-01 15:35:54 +02:00
committed by GitHub
parent d3130f0d39
commit e1b2689c3a
40 changed files with 4125 additions and 384 deletions

View File

@@ -0,0 +1,178 @@
#!/usr/bin/env bash
# AzerothCore BATS Assertions Library
# Custom assertions for AzerothCore testing
# Assert that a binary exists and is executable
assert_binary_exists() {
local binary_path="$1"
local message="${2:-Binary should exist and be executable}"
if [[ ! -f "$binary_path" ]]; then
echo "Binary not found: $binary_path"
echo "$message"
return 1
fi
if [[ ! -x "$binary_path" ]]; then
echo "Binary not executable: $binary_path"
echo "$message"
return 1
fi
}
# Assert that output contains specific AzerothCore patterns
assert_acore_server_started() {
local output="$1"
local server_type="$2"
local message="${3:-Server should show startup message}"
if [[ ! "$output" =~ $server_type.*starting ]]; then
echo "Server start message not found for $server_type"
echo "Expected pattern: '$server_type.*starting'"
echo "Actual output: $output"
echo "$message"
return 1
fi
}
# Assert that configuration file was loaded
assert_config_loaded() {
local output="$1"
local config_file="$2"
local message="${3:-Configuration file should be loaded}"
if [[ ! "$output" =~ config.*$config_file ]] && [[ ! "$output" =~ $config_file ]]; then
echo "Configuration file loading not detected: $config_file"
echo "Expected to find: config.*$config_file OR $config_file"
echo "Actual output: $output"
echo "$message"
return 1
fi
}
# Assert that a process exited with expected code
assert_exit_code() {
local actual_code="$1"
local expected_code="$2"
local message="${3:-Process should exit with expected code}"
if [[ "$actual_code" -ne "$expected_code" ]]; then
echo "Expected exit code: $expected_code"
echo "Actual exit code: $actual_code"
echo "$message"
return 1
fi
}
# Assert that output contains specific error pattern
assert_error_message() {
local output="$1"
local error_pattern="$2"
local message="${3:-Output should contain expected error message}"
if [[ ! "$output" =~ $error_pattern ]]; then
echo "Expected error pattern not found: $error_pattern"
echo "Actual output: $output"
echo "$message"
return 1
fi
}
# Assert that a file was created
assert_file_created() {
local file_path="$1"
local message="${2:-File should be created}"
if [[ ! -f "$file_path" ]]; then
echo "File not created: $file_path"
echo "$message"
return 1
fi
}
# Assert that a directory was created
assert_directory_created() {
local dir_path="$1"
local message="${2:-Directory should be created}"
if [[ ! -d "$dir_path" ]]; then
echo "Directory not created: $dir_path"
echo "$message"
return 1
fi
}
# Assert that output contains success message
assert_success_message() {
local output="$1"
local success_pattern="${2:-success|completed|finished|done}"
local message="${3:-Output should contain success message}"
if [[ ! "$output" =~ $success_pattern ]]; then
echo "Success message not found"
echo "Expected pattern: $success_pattern"
echo "Actual output: $output"
echo "$message"
return 1
fi
}
# Assert that build was successful
assert_build_success() {
local output="$1"
local message="${2:-Build should complete successfully}"
local build_success_patterns="Build completed|compilation successful|build.*success|make.*success"
assert_success_message "$output" "$build_success_patterns" "$message"
}
# Assert that server is responsive
assert_server_responsive() {
local output="$1"
local server_type="$2"
local message="${3:-Server should be responsive}"
if [[ ! "$output" =~ $server_type.*initialized ]] && [[ ! "$output" =~ $server_type.*ready ]]; then
echo "Server responsiveness not detected for $server_type"
echo "Expected pattern: '$server_type.*initialized' OR '$server_type.*ready'"
echo "Actual output: $output"
echo "$message"
return 1
fi
}
# Assert that timeout occurred (for long-running processes)
assert_timeout() {
local exit_code="$1"
local message="${2:-Process should timeout as expected}"
if [[ "$exit_code" -ne 124 ]]; then
echo "Expected timeout (exit code 124)"
echo "Actual exit code: $exit_code"
echo "$message"
return 1
fi
}
# Assert that log file contains expected content
assert_log_contains() {
local log_file="$1"
local expected_content="$2"
local message="${3:-Log file should contain expected content}"
if [[ ! -f "$log_file" ]]; then
echo "Log file not found: $log_file"
echo "$message"
return 1
fi
if ! grep -q "$expected_content" "$log_file"; then
echo "Expected content not found in log: $expected_content"
echo "Log file: $log_file"
echo "Log contents:"
cat "$log_file" | head -20
echo "$message"
return 1
fi
}

View File

@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# AzerothCore BATS Support Library
# Additional helper functions for BATS testing
# Load common test utilities
source "$(dirname "${BASH_SOURCE[0]}")/../helpers/test_common.sh"
# Standard setup for all AzerothCore tests
acore_test_setup() {
setup_test_env
create_acore_binaries
create_acore_configs
}
# Standard teardown for all AzerothCore tests
acore_test_teardown() {
cleanup_test_env
}
# Quick setup for startup script tests
startup_scripts_setup() {
acore_test_setup
create_test_script_config "test" "test-server"
# Create additional test binary for startup scripts
create_test_binary "test-server" 0 2 "Test server starting with config:"
# Create the test-server.conf file that tests expect
cat > "$TEST_DIR/test-server.conf" << EOF
# Test server configuration file
# Generated by AzerothCore test framework
Database.Info = "127.0.0.1;3306;acore;acore;acore_world"
LoginDatabaseInfo = "127.0.0.1;3306;acore;acore;acore_auth"
CharacterDatabaseInfo = "127.0.0.1;3306;acore;acore;acore_characters"
EOF
}
# Quick setup for compiler tests
compiler_setup() {
acore_test_setup
# Create mock build tools
create_test_binary "gcc" 0 1
create_test_binary "g++" 0 1
create_test_binary "ninja" 0 2
# Create mock CMake files
mkdir -p "$TEST_DIR/build"
touch "$TEST_DIR/build/CMakeCache.txt"
echo "CMAKE_BUILD_TYPE:STRING=RelWithDebInfo" > "$TEST_DIR/build/CMakeCache.txt"
}
# Quick setup for docker tests
docker_setup() {
acore_test_setup
# Create mock docker commands
create_test_binary "docker" 0 1 "Docker container started"
create_test_binary "docker-compose" 0 2 "Docker Compose services started"
# Create test docker files
cat > "$TEST_DIR/Dockerfile" << 'EOF'
FROM ubuntu:20.04
RUN apt-get update
EOF
cat > "$TEST_DIR/docker-compose.yml" << 'EOF'
version: '3.8'
services:
test-service:
image: ubuntu:20.04
EOF
}
# Quick setup for extractor tests
extractor_setup() {
acore_test_setup
# Create mock client data directories
mkdir -p "$TEST_DIR/client"/{Maps,vmaps,mmaps,dbc}
# Create some test data files
echo "Test map data" > "$TEST_DIR/client/Maps/test.map"
echo "Test DBC data" > "$TEST_DIR/client/dbc/test.dbc"
}
# Helper to run command with timeout and capture output
run_with_timeout() {
local timeout_duration="$1"
shift
run timeout "$timeout_duration" "$@"
}
# Helper to check if a process is running
process_running() {
local process_name="$1"
pgrep -f "$process_name" >/dev/null 2>&1
}
# Helper to wait for a condition
wait_for_condition() {
local condition="$1"
local timeout="${2:-10}"
local interval="${3:-1}"
local count=0
while ! eval "$condition"; do
sleep "$interval"
count=$((count + interval))
if [[ $count -ge $timeout ]]; then
return 1
fi
done
return 0
}