#!/bin/bash
# 验证测试特性组合的脚本
#
# 此脚本验证所有测试配置是否包含必需的数据库驱动和运行时特性

set -e

echo "=========================================="
echo "验证测试特性组合"
echo "=========================================="
echo ""

# 检查 Cargo.toml 中的测试配置
echo "1. 检查 Cargo.toml 中的测试配置..."
echo ""

# 检查是否有测试缺少数据库驱动特性
missing_db_driver=$(grep -A 2 '^\[\[test\]\]' Cargo.toml | grep -B 1 'required-features' | grep -v 'required-features' | grep -v '^\[\[test\]\]' | grep -v '^--$' | wc -l)

if [ $missing_db_driver -gt 0 ]; then
    echo "❌ 发现 $missing_db_driver 个测试可能缺少数据库驱动特性"
    exit 1
else
    echo "✅ 所有测试都配置了数据库驱动特性"
fi

echo ""

# 检查是否有测试缺少运行时特性
missing_runtime=$(grep -A 2 '^\[\[test\]\]' Cargo.toml | grep 'required-features' | grep -v 'runtime-tokio-rustls' | wc -l)

if [ $missing_runtime -gt 0 ]; then
    echo "❌ 发现 $missing_runtime 个测试缺少运行时特性 (runtime-tokio-rustls)"
    exit 1
else
    echo "✅ 所有测试都配置了运行时特性"
fi

echo ""
echo "2. 验证 Makefile 中的测试命令..."
echo ""

# 检查 Makefile 中的测试命令
if grep -q 'test-sqlite:' Makefile && grep -q 'test-postgres:' Makefile && grep -q 'test-mysql:' Makefile; then
    echo "✅ Makefile 包含所有数据库测试命令"
else
    echo "❌ Makefile 缺少部分数据库测试命令"
    exit 1
fi

if grep -q 'test-minimal:' Makefile && grep -q 'test-microservice:' Makefile && grep -q 'test-ultra-minimal:' Makefile; then
    echo "✅ Makefile 包含所有预设配置测试命令"
else
    echo "❌ Makefile 缺少部分预设配置测试命令"
    exit 1
fi

echo ""
echo "=========================================="
echo "✅ 所有验证通过！"
echo "=========================================="