i18n+filtering fork - fluent-templates v2
at main 5.6 kB view raw
1#!/bin/bash 2 3# Comprehensive i18n Test Suite Runner 4# Phase 4 Task G - Smokesignal i18n Integration Tests 5 6set -e 7 8# Colors for output 9RED='\033[0;31m' 10GREEN='\033[0;32m' 11YELLOW='\033[1;33m' 12BLUE='\033[0;34m' 13NC='\033[0m' # No Color 14 15# Test configuration 16TEST_DATABASE_URL=${DATABASE_URL:-"postgresql://localhost/smokesignal_test"} 17COVERAGE_THRESHOLD=90 18PERFORMANCE_MODE=${PERFORMANCE_MODE:-"false"} 19 20echo -e "${BLUE}🧪 Smokesignal i18n Test Suite Runner${NC}" 21echo "==================================================" 22 23# Function to print section headers 24print_section() { 25 echo -e "\n${BLUE}📋 $1${NC}" 26 echo "----------------------------------------" 27} 28 29# Function to print success 30print_success() { 31 echo -e "${GREEN}$1${NC}" 32} 33 34# Function to print warning 35print_warning() { 36 echo -e "${YELLOW}⚠️ $1${NC}" 37} 38 39# Function to print error 40print_error() { 41 echo -e "${RED}$1${NC}" 42} 43 44# Check prerequisites 45print_section "Checking Prerequisites" 46 47# Check if Rust is installed 48if ! command -v cargo &> /dev/null; then 49 print_error "Cargo not found. Please install Rust." 50 exit 1 51fi 52print_success "Rust/Cargo found" 53 54# Check if database URL is set (optional) 55if [ -z "$DATABASE_URL" ]; then 56 print_warning "DATABASE_URL not set. Database-dependent tests will be skipped." 57else 58 print_success "Database URL configured" 59fi 60 61# Build the project first 62print_section "Building Project" 63echo "Building smokesignal with dev dependencies..." 64if cargo build --tests; then 65 print_success "Project built successfully" 66else 67 print_error "Build failed" 68 exit 1 69fi 70 71# Function to run tests with timing 72run_test_suite() { 73 local test_name="$1" 74 local test_pattern="$2" 75 local additional_flags="$3" 76 77 echo -e "\n${YELLOW}Running $test_name...${NC}" 78 start_time=$(date +%s) 79 80 if cargo test $test_pattern $additional_flags -- --nocapture; then 81 end_time=$(date +%s) 82 duration=$((end_time - start_time)) 83 print_success "$test_name completed in ${duration}s" 84 return 0 85 else 86 print_error "$test_name failed" 87 return 1 88 fi 89} 90 91# Run unit tests 92print_section "Running Unit Tests" 93 94echo "Running FacetCalculator i18n tests..." 95run_test_suite "Facets i18n Tests" "--test facets_i18n_test" "" 96 97echo "Running FilteringService i18n tests..." 98run_test_suite "Service i18n Tests" "--test service_i18n_test" "" 99 100echo "Running HTTP Handler i18n tests..." 101run_test_suite "HTTP Handler i18n Tests" "--test filter_handler_i18n_test" "" 102 103# Run integration tests 104print_section "Running Integration Tests" 105 106echo "Running comprehensive integration tests..." 107run_test_suite "Integration Tests" "--test filtering_i18n_integration_test" "" 108 109# Run performance benchmarks if requested 110if [ "$PERFORMANCE_MODE" = "true" ]; then 111 print_section "Running Performance Benchmarks" 112 113 echo "Running performance benchmarks in release mode..." 114 run_test_suite "Performance Benchmarks" "--test filtering_i18n_integration_test --release" "benchmark_" 115 116 echo "Running stress tests in release mode..." 117 run_test_suite "Stress Tests" "--test filtering_i18n_integration_test --release" "stress_test_" 118fi 119 120# Generate coverage report if tarpaulin is available 121print_section "Generating Coverage Report" 122 123if command -v cargo-tarpaulin &> /dev/null; then 124 echo "Generating test coverage report..." 125 start_time=$(date +%s) 126 127 if cargo tarpaulin \ 128 --test "facets_i18n_test" \ 129 --test "service_i18n_test" \ 130 --test "filter_handler_i18n_test" \ 131 --test "filtering_i18n_integration_test" \ 132 --out Html --output-dir coverage/ \ 133 --line --branch --count; then 134 135 end_time=$(date +%s) 136 duration=$((end_time - start_time)) 137 print_success "Coverage report generated in ${duration}s" 138 print_success "Coverage report saved to coverage/tarpaulin-report.html" 139 140 # Extract coverage percentage (if available) 141 if [ -f "coverage/tarpaulin-report.html" ]; then 142 echo "Coverage report available at: coverage/tarpaulin-report.html" 143 fi 144 else 145 print_warning "Coverage report generation failed (optional)" 146 fi 147else 148 print_warning "cargo-tarpaulin not found. Install with: cargo install cargo-tarpaulin" 149fi 150 151# Run specific test categories based on arguments 152if [ $# -gt 0 ]; then 153 print_section "Running Custom Test Patterns" 154 155 for pattern in "$@"; do 156 echo "Running custom test pattern: $pattern" 157 run_test_suite "Custom: $pattern" "--test" "$pattern" 158 done 159fi 160 161# Summary 162print_section "Test Summary" 163 164echo "All test suites completed successfully!" 165echo "" 166echo "📊 Test Coverage Areas:" 167echo " ✅ FacetCalculator i18n methods" 168echo " ✅ FilteringService cache key generation" 169echo " ✅ HTTP locale extraction and parsing" 170echo " ✅ End-to-end i18n workflow" 171echo " ✅ Performance benchmarks" 172echo " ✅ Error handling and edge cases" 173echo " ✅ Memory usage validation" 174echo " ✅ Concurrent operation safety" 175echo "" 176echo "🎯 Coverage Target: ${COVERAGE_THRESHOLD}%" 177echo "🚀 Performance Benchmarks: $([ "$PERFORMANCE_MODE" = "true" ] && echo "Completed" || echo "Skipped (use PERFORMANCE_MODE=true)")" 178echo "" 179 180if [ -f "coverage/tarpaulin-report.html" ]; then 181 echo "📈 Detailed coverage report: coverage/tarpaulin-report.html" 182fi 183 184print_success "i18n Test Suite execution completed!" 185 186# Exit codes: 187# 0 - All tests passed 188# 1 - Some tests failed 189echo -e "\n${GREEN}🎉 All i18n tests completed successfully!${NC}" 190exit 0