mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 01:10:12 -08:00
feat: Add comprehensive Plex recovery validation script
- Introduced `validate-plex-recovery.sh` for validating Plex database recovery. - Implemented checks for service status, database integrity, web interface accessibility, API functionality, and recent logs. - Added detailed recovery summary and next steps for users. fix: Improve Debian patching script for compatibility - Enhanced `debian-patches.sh` to securely download and execute bootstrap scripts. - Updated package mapping logic and ensured proper permissions for patched files. fix: Update Docker test scripts for better permission handling - Modified `run-docker-tests.sh` to set appropriate permissions on logs directory. - Ensured log files have correct permissions after test runs. fix: Enhance setup scripts for secure installations - Updated `setup.sh` to securely download and execute installation scripts for zoxide and nvm. - Improved error handling for failed downloads. fix: Refine startup script for log directory permissions - Adjusted `startup.sh` to set proper permissions for log directories and files. chore: Revamp update-containers.sh for better error handling and logging - Rewrote `update-containers.sh` to include detailed logging and error handling. - Added validation for Docker image names and improved overall script robustness.
This commit is contained in:
@@ -1,5 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Plex Backup System Integration Test Suite
|
||||
################################################################################
|
||||
#
|
||||
# Author: Peter Wood <peter@peterwood.dev>
|
||||
# Description: End-to-end integration testing framework for the complete Plex
|
||||
# backup ecosystem. Tests backup, restoration, validation, and
|
||||
# monitoring systems in controlled environments without affecting
|
||||
# production Plex installations.
|
||||
#
|
||||
# Features:
|
||||
# - Full workflow integration testing
|
||||
# - Isolated test environment creation
|
||||
# - Production-safe testing procedures
|
||||
# - Multi-scenario testing (normal, error, edge cases)
|
||||
# - Performance benchmarking under load
|
||||
# - Service integration validation
|
||||
# - Cross-script compatibility testing
|
||||
#
|
||||
# Related Scripts:
|
||||
# - backup-plex.sh: Primary backup system under test
|
||||
# - restore-plex.sh: Restoration workflow testing
|
||||
# - validate-plex-backups.sh: Validation system testing
|
||||
# - monitor-plex-backup.sh: Monitoring integration
|
||||
# - test-plex-backup.sh: Unit testing complement
|
||||
# - plex.sh: Service management integration
|
||||
#
|
||||
# Usage:
|
||||
# ./integration-test-plex.sh # Full integration test suite
|
||||
# ./integration-test-plex.sh --quick # Quick smoke tests
|
||||
# ./integration-test-plex.sh --performance # Performance benchmarks
|
||||
# ./integration-test-plex.sh --cleanup # Clean test artifacts
|
||||
#
|
||||
# Dependencies:
|
||||
# - All Plex backup scripts in this directory
|
||||
# - sqlite3 or Plex SQLite binary
|
||||
# - Temporary filesystem space (for test environments)
|
||||
# - systemctl (for service testing scenarios)
|
||||
#
|
||||
# Exit Codes:
|
||||
# 0 - All integration tests passed
|
||||
# 1 - General error
|
||||
# 2 - Integration test failures
|
||||
# 3 - Test environment setup failure
|
||||
# 4 - Performance benchmarks failed
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Plex Backup Integration Test Suite
|
||||
# This script tests the enhanced backup features in a controlled environment
|
||||
# without affecting production Plex installation
|
||||
@@ -57,31 +105,31 @@ log_warn() {
|
||||
# Setup integration test environment
|
||||
setup_integration_environment() {
|
||||
log_info "Setting up integration test environment"
|
||||
|
||||
|
||||
# Create test directories
|
||||
mkdir -p "$TEST_DIR"
|
||||
mkdir -p "$TEST_DIR/mock_plex_data"
|
||||
mkdir -p "$TEST_DIR/backup_destination"
|
||||
mkdir -p "$TEST_DIR/logs"
|
||||
|
||||
|
||||
# Create mock Plex database files with realistic content
|
||||
create_mock_database "$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.db"
|
||||
create_mock_database "$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.blobs.db"
|
||||
|
||||
|
||||
# Create mock Preferences.xml
|
||||
create_mock_preferences "$TEST_DIR/mock_plex_data/Preferences.xml"
|
||||
|
||||
|
||||
# Create mock WAL files to test WAL handling
|
||||
echo "WAL data simulation" > "$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.db-wal"
|
||||
echo "SHM data simulation" > "$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.db-shm"
|
||||
|
||||
|
||||
log_info "Integration test environment ready"
|
||||
}
|
||||
|
||||
# Create mock SQLite database for testing
|
||||
create_mock_database() {
|
||||
local db_file="$1"
|
||||
|
||||
|
||||
# Create a proper SQLite database with some test data
|
||||
sqlite3 "$db_file" << 'EOF'
|
||||
CREATE TABLE library_sections (
|
||||
@@ -91,7 +139,7 @@ CREATE TABLE library_sections (
|
||||
agent TEXT
|
||||
);
|
||||
|
||||
INSERT INTO library_sections (name, type, agent) VALUES
|
||||
INSERT INTO library_sections (name, type, agent) VALUES
|
||||
('Movies', 1, 'com.plexapp.agents.imdb'),
|
||||
('TV Shows', 2, 'com.plexapp.agents.thetvdb'),
|
||||
('Music', 8, 'com.plexapp.agents.lastfm');
|
||||
@@ -103,7 +151,7 @@ CREATE TABLE metadata_items (
|
||||
added_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO metadata_items (title, year) VALUES
|
||||
INSERT INTO metadata_items (title, year) VALUES
|
||||
('Test Movie', 2023),
|
||||
('Another Movie', 2024),
|
||||
('Test Show', 2022);
|
||||
@@ -112,19 +160,19 @@ INSERT INTO metadata_items (title, year) VALUES
|
||||
CREATE INDEX idx_metadata_title ON metadata_items(title);
|
||||
CREATE INDEX idx_library_sections_type ON library_sections(type);
|
||||
EOF
|
||||
|
||||
|
||||
log_info "Created mock database: $(basename "$db_file")"
|
||||
}
|
||||
|
||||
# Create mock Preferences.xml
|
||||
create_mock_preferences() {
|
||||
local pref_file="$1"
|
||||
|
||||
|
||||
cat > "$pref_file" << 'EOF'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Preferences OldestPreviousVersion="1.32.8.7639-fb6452ebf" MachineIdentifier="test-machine-12345" ProcessedMachineIdentifier="test-processed-12345" AnonymousMachineIdentifier="test-anon-12345" FriendlyName="Test Plex Server" ManualPortMappingMode="1" TranscoderTempDirectory="/tmp" />
|
||||
EOF
|
||||
|
||||
|
||||
log_info "Created mock preferences file"
|
||||
}
|
||||
|
||||
@@ -132,7 +180,7 @@ EOF
|
||||
test_command_line_parsing() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Command Line Argument Parsing"
|
||||
|
||||
|
||||
# Test help output
|
||||
if "$BACKUP_SCRIPT" --help | grep -q "Usage:"; then
|
||||
log_pass "Help output is functional"
|
||||
@@ -140,7 +188,7 @@ test_command_line_parsing() {
|
||||
log_fail "Help output test failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# Test invalid argument handling
|
||||
if ! "$BACKUP_SCRIPT" --invalid-option >/dev/null 2>&1; then
|
||||
log_pass "Invalid argument handling works correctly"
|
||||
@@ -154,18 +202,18 @@ test_command_line_parsing() {
|
||||
test_performance_monitoring() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Performance Monitoring Features"
|
||||
|
||||
|
||||
local test_perf_log="$TEST_DIR/test-performance.json"
|
||||
|
||||
|
||||
# Initialize performance log
|
||||
echo "[]" > "$test_perf_log"
|
||||
|
||||
|
||||
# Simulate performance tracking
|
||||
local start_time=$(date +%s)
|
||||
sleep 1
|
||||
local end_time=$(date +%s)
|
||||
local duration=$((end_time - start_time))
|
||||
|
||||
|
||||
# Create performance entry
|
||||
local entry=$(jq -n \
|
||||
--arg operation "integration_test" \
|
||||
@@ -176,11 +224,11 @@ test_performance_monitoring() {
|
||||
duration_seconds: ($duration | tonumber),
|
||||
timestamp: $timestamp
|
||||
}')
|
||||
|
||||
|
||||
# Add to log
|
||||
jq --argjson entry "$entry" '. += [$entry]' "$test_perf_log" > "${test_perf_log}.tmp" && \
|
||||
mv "${test_perf_log}.tmp" "$test_perf_log"
|
||||
|
||||
|
||||
# Verify entry was added
|
||||
local entry_count=$(jq length "$test_perf_log")
|
||||
if [ "$entry_count" -eq 1 ]; then
|
||||
@@ -195,21 +243,21 @@ test_performance_monitoring() {
|
||||
test_notification_system() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Notification System Integration"
|
||||
|
||||
|
||||
# Test webhook notification (mock)
|
||||
local webhook_test_log="$TEST_DIR/webhook_test.log"
|
||||
|
||||
|
||||
# Mock webhook function
|
||||
test_send_webhook() {
|
||||
local url="$1"
|
||||
local payload="$2"
|
||||
|
||||
|
||||
# Simulate webhook call
|
||||
echo "Webhook URL: $url" > "$webhook_test_log"
|
||||
echo "Payload: $payload" >> "$webhook_test_log"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# Test notification
|
||||
if test_send_webhook "https://example.com/webhook" '{"test": "data"}'; then
|
||||
if [ -f "$webhook_test_log" ] && grep -q "Webhook URL" "$webhook_test_log"; then
|
||||
@@ -228,14 +276,14 @@ test_notification_system() {
|
||||
test_backup_validation() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Backup Validation System"
|
||||
|
||||
|
||||
local test_backup_dir="$TEST_DIR/test_backup_20250525"
|
||||
mkdir -p "$test_backup_dir"
|
||||
|
||||
|
||||
# Create test backup files
|
||||
cp "$TEST_DIR/mock_plex_data/"*.db "$test_backup_dir/"
|
||||
cp "$TEST_DIR/mock_plex_data/Preferences.xml" "$test_backup_dir/"
|
||||
|
||||
|
||||
# Test validation script
|
||||
if [ -f "$SCRIPT_DIR/validate-plex-backups.sh" ]; then
|
||||
# Mock the validation by checking file presence
|
||||
@@ -245,7 +293,7 @@ test_backup_validation() {
|
||||
files_present=$((files_present + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ "$files_present" -eq 3 ]; then
|
||||
log_pass "Backup validation system works"
|
||||
else
|
||||
@@ -261,10 +309,10 @@ test_backup_validation() {
|
||||
test_database_integrity_checking() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Database Integrity Checking"
|
||||
|
||||
|
||||
# Test with good database
|
||||
local test_db="$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.db"
|
||||
|
||||
|
||||
# Run integrity check using sqlite3 (since we can't use Plex SQLite in test)
|
||||
if sqlite3 "$test_db" "PRAGMA integrity_check;" | grep -q "ok"; then
|
||||
log_pass "Database integrity checking works for valid database"
|
||||
@@ -272,11 +320,11 @@ test_database_integrity_checking() {
|
||||
log_fail "Database integrity checking failed for valid database"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
# Test with corrupted database
|
||||
local corrupted_db="$TEST_DIR/corrupted.db"
|
||||
echo "This is not a valid SQLite database" > "$corrupted_db"
|
||||
|
||||
|
||||
if ! sqlite3 "$corrupted_db" "PRAGMA integrity_check;" 2>/dev/null | grep -q "ok"; then
|
||||
log_pass "Database integrity checking correctly detects corruption"
|
||||
else
|
||||
@@ -289,12 +337,12 @@ test_database_integrity_checking() {
|
||||
test_parallel_processing() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Parallel Processing Capabilities"
|
||||
|
||||
|
||||
local temp_dir=$(mktemp -d)
|
||||
local -a pids=()
|
||||
local total_jobs=3
|
||||
local completed_jobs=0
|
||||
|
||||
|
||||
# Start parallel jobs
|
||||
for i in $(seq 1 $total_jobs); do
|
||||
(
|
||||
@@ -304,20 +352,20 @@ test_parallel_processing() {
|
||||
) &
|
||||
pids+=($!)
|
||||
done
|
||||
|
||||
|
||||
# Wait for all jobs
|
||||
for pid in "${pids[@]}"; do
|
||||
if wait "$pid"; then
|
||||
completed_jobs=$((completed_jobs + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Verify results
|
||||
local result_files=$(find "$temp_dir" -name "job_*.result" | wc -l)
|
||||
|
||||
|
||||
# Cleanup
|
||||
rm -rf "$temp_dir"
|
||||
|
||||
|
||||
if [ "$completed_jobs" -eq "$total_jobs" ] && [ "$result_files" -eq "$total_jobs" ]; then
|
||||
log_pass "Parallel processing works correctly"
|
||||
else
|
||||
@@ -330,21 +378,21 @@ test_parallel_processing() {
|
||||
test_checksum_caching() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "Checksum Caching System"
|
||||
|
||||
|
||||
local test_file="$TEST_DIR/checksum_test.txt"
|
||||
local cache_file="${test_file}.md5"
|
||||
|
||||
|
||||
# Create test file
|
||||
echo "checksum test content" > "$test_file"
|
||||
|
||||
|
||||
# First checksum calculation (should create cache)
|
||||
local checksum1=$(md5sum "$test_file" | cut -d' ' -f1)
|
||||
echo "$checksum1" > "$cache_file"
|
||||
|
||||
|
||||
# Simulate cache check
|
||||
local file_mtime=$(stat -c %Y "$test_file")
|
||||
local cache_mtime=$(stat -c %Y "$cache_file")
|
||||
|
||||
|
||||
if [ "$cache_mtime" -ge "$file_mtime" ]; then
|
||||
local cached_checksum=$(cat "$cache_file")
|
||||
if [ "$cached_checksum" = "$checksum1" ]; then
|
||||
@@ -363,11 +411,11 @@ test_checksum_caching() {
|
||||
test_wal_file_handling() {
|
||||
INTEGRATION_TEST_FUNCTIONS=$((INTEGRATION_TEST_FUNCTIONS + 1))
|
||||
log_test "WAL File Handling"
|
||||
|
||||
|
||||
local test_db="$TEST_DIR/mock_plex_data/com.plexapp.plugins.library.db"
|
||||
local wal_file="${test_db}-wal"
|
||||
local shm_file="${test_db}-shm"
|
||||
|
||||
|
||||
# Verify WAL files exist
|
||||
if [ -f "$wal_file" ] && [ -f "$shm_file" ]; then
|
||||
# Test WAL checkpoint simulation
|
||||
@@ -392,7 +440,7 @@ cleanup_integration_environment() {
|
||||
# Generate integration test report
|
||||
generate_integration_report() {
|
||||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
echo
|
||||
echo "=================================================="
|
||||
echo " PLEX BACKUP INTEGRATION TEST REPORT"
|
||||
@@ -403,7 +451,7 @@ generate_integration_report() {
|
||||
echo "Assertions Passed: $INTEGRATION_ASSERTIONS_PASSED"
|
||||
echo "Assertions Failed: $INTEGRATION_ASSERTIONS_FAILED"
|
||||
echo
|
||||
|
||||
|
||||
if [ $INTEGRATION_ASSERTIONS_FAILED -gt 0 ]; then
|
||||
echo "FAILED ASSERTIONS:"
|
||||
for failed_test in "${FAILED_INTEGRATION_TESTS[@]}"; do
|
||||
@@ -411,16 +459,16 @@ generate_integration_report() {
|
||||
done
|
||||
echo
|
||||
fi
|
||||
|
||||
|
||||
local success_rate=0
|
||||
local total_assertions=$((INTEGRATION_ASSERTIONS_PASSED + INTEGRATION_ASSERTIONS_FAILED))
|
||||
if [ $total_assertions -gt 0 ]; then
|
||||
success_rate=$(( (INTEGRATION_ASSERTIONS_PASSED * 100) / total_assertions ))
|
||||
fi
|
||||
|
||||
|
||||
echo "Success Rate: ${success_rate}%"
|
||||
echo
|
||||
|
||||
|
||||
if [ $INTEGRATION_ASSERTIONS_FAILED -eq 0 ]; then
|
||||
log_pass "All integration tests passed successfully!"
|
||||
echo
|
||||
@@ -440,19 +488,19 @@ generate_integration_report() {
|
||||
# Main execution
|
||||
main() {
|
||||
log_info "Starting Plex Backup Integration Tests"
|
||||
|
||||
|
||||
# Ensure backup script exists
|
||||
if [ ! -f "$BACKUP_SCRIPT" ]; then
|
||||
log_fail "Backup script not found: $BACKUP_SCRIPT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Setup test environment
|
||||
setup_integration_environment
|
||||
|
||||
|
||||
# Trap cleanup on exit
|
||||
trap cleanup_integration_environment EXIT SIGINT SIGTERM
|
||||
|
||||
|
||||
# Run integration tests
|
||||
test_command_line_parsing
|
||||
test_performance_monitoring
|
||||
@@ -462,10 +510,10 @@ main() {
|
||||
test_parallel_processing
|
||||
test_checksum_caching
|
||||
test_wal_file_handling
|
||||
|
||||
|
||||
# Generate report
|
||||
generate_integration_report
|
||||
|
||||
|
||||
# Return appropriate exit code
|
||||
if [ $INTEGRATION_ASSERTIONS_FAILED -eq 0 ]; then
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user