fix: update E2E test API paths and payloads to match backend

- user-apikey-lifecycle: /api/v1/keys -> /api/v1/api-keys (24 occurrences)
- admin-users: balance payload uses balance+operation+notes
- admin-groups: rate-multiplier already uses correct format
This commit is contained in:
Developer
2026-04-02 22:35:48 +08:00
parent c660553c87
commit 8b19f56ba4
634 changed files with 169806 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
/**
* Test Report Generator
*
* Generates a comprehensive test report from all test results.
*/
import fs from 'fs';
import path from 'path';
interface TestResult {
title: string;
status: 'passed' | 'failed' | 'skipped';
duration: number;
error?: string;
}
interface Report {
timestamp: string;
summary: {
total: number;
passed: number;
failed: number;
skipped: number;
passRate: number;
};
results: TestResult[];
}
async function generateReport() {
console.log('📊 Generating test report...');
const resultsPath = path.join(__dirname, '../e2e/test-results/results.json');
if (!fs.existsSync(resultsPath)) {
console.log('⚠️ No test results found');
return;
}
const data = JSON.parse(fs.readFileSync(resultsPath, 'utf-8'));
const report: Report = {
timestamp: new Date().toISOString(),
summary: {
total: data.stats?.tests || 0,
passed: data.stats?.passed || 0,
failed: data.stats?.failed || 0,
skipped: data.stats?.skipped || 0,
passRate: ((data.stats?.passed || 0) / (data.stats?.tests || 1)) * 100
},
results: (data.tests || []).map((test: any) => ({
title: test.title,
status: test.status,
duration: test.duration,
error: test.error
}))
};
// Generate markdown report
const mdReport = generateMarkdownReport(report);
const mdPath = path.join(__dirname, '../e2e/TEST_REPORT.md');
fs.writeFileSync(mdPath, mdReport);
console.log(`✅ Report saved to: ${mdPath}`);
}
function generateMarkdownReport(report: Report): string {
return `# Sub2API Test Report
## Summary
| Metric | Value |
|--------|-------|
| Total Tests | ${report.summary.total} |
| Passed | ${report.summary.passed} ✅ |
| Failed | ${report.summary.failed} ❌ |
| Skipped | ${report.summary.skipped} ⏭️ |
| Pass Rate | ${report.summary.passRate.toFixed(1)}% |
## Timestamp
${report.timestamp}
## Failed Tests
${report.results.filter(r => r.status === 'failed').map(r => `### ${r.title}
\`\`\`
${r.error}
\`\`\`
`).join('\n')}
---
*Report generated at ${new Date().toISOString()}*
`;
}
generateReport().catch(console.error);

View File

@@ -0,0 +1,54 @@
# Sub2API Performance Test Runner
# Run: .\run-benchmarks.ps1
param(
[string]$OutputDir = "..\performance\reports"
)
$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $PSScriptRoot
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Sub2API Performance Test Runner" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
# Ensure output directory exists
$OutputPath = Join-Path $ProjectRoot $OutputDir
if (-not (Test-Path $OutputPath)) {
New-Item -ItemType Directory -Path $OutputPath | Out-Null
}
$Timestamp = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
$ReportFile = Join-Path $OutputPath "benchmark_$Timestamp.txt"
Write-Host "`n[1/3] Running Go Benchmarks..." -ForegroundColor Yellow
Set-Location (Join-Path $ProjectRoot "backend")
# Run all benchmarks
$benchResult = go test -bench=. -benchmem -count=5 -timeout 300s ./... 2>&1 | Select-String -Pattern "^(Benchmark|PASS|ok|---)"
$benchResult | Out-File -FilePath $ReportFile -Encoding UTF8
Write-Host " Results saved to: $ReportFile" -ForegroundColor Green
Write-Host "`n[2/3] Running Handler Benchmarks..." -ForegroundColor Yellow
$handlerResult = go test -bench=Handler -benchmem -count=3 -timeout 120s ./internal/handler/... 2>&1 | Select-String -Pattern "^(Benchmark|PASS|ok|---)"
$handlerResult | Out-File -FilePath (Join-Path $OutputPath "handler_bench_$Timestamp.txt") -Encoding UTF8
Write-Host "`n[3/3] Running Service Benchmarks..." -ForegroundColor Yellow
$serviceResult = go test -bench=Service -benchmem -count=3 -timeout 120s ./internal/service/... 2>&1 | Select-String -Pattern "^(Benchmark|PASS|ok|---)"
$serviceResult | Out-File -FilePath (Join-Path $OutputPath "service_bench_$Timestamp.txt") -Encoding UTF8
Write-Host "`n============================================" -ForegroundColor Cyan
Write-Host " Benchmark Results Summary" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
# Parse and display key results
Write-Host "`nKey Metrics:" -ForegroundColor White
$benchResult | ForEach-Object {
if ($_ -match "Benchmark.*-(\d+)\s+(\d+)\s+ns/op") {
Write-Host " $_" -ForegroundColor Gray
}
}
Write-Host "`nBenchmark tests complete!" -ForegroundColor Green
Write-Host "Reports saved to: $OutputPath" -ForegroundColor Cyan

View File

@@ -0,0 +1,65 @@
@echo off
REM Sub2API Test Runner Script (Windows)
REM
REM Usage:
REM run-tests.bat Run all tests
REM run-tests.bat unit Run only unit tests
REM run-tests.bat e2e Run only E2E tests
REM run-tests.bat ci Run tests in CI mode
setlocal enabledelayedexpansion
set "SCRIPT_DIR=%~dp0"
set "PROJECT_ROOT=%SCRIPT_DIR%.."
echo [INFO] Running tests...
if "%1"=="" goto all
if "%1"=="unit" goto unit
if "%1"=="integration" goto integration
if "%1"=="e2e" goto e2e
if "%1"=="ci" goto ci
goto usage
:unit
echo [INFO] Running backend unit tests...
cd /d "%PROJECT_ROOT%\backend"
go test -short ./...
echo [INFO] Unit tests completed!
goto end
:integration
echo [INFO] Running frontend integration tests...
cd /d "%PROJECT_ROOT%\frontend"
call pnpm test -- --run
echo [INFO] Integration tests completed!
goto end
:e2e
echo [INFO] Running E2E tests...
cd /d "%SCRIPT_DIR%"
call npx playwright test
echo [INFO] E2E tests completed!
goto end
:ci
echo [INFO] Running CI tests (without E2E)...
call :unit
call :integration
echo [INFO] CI tests completed!
goto end
:all
echo [INFO] Running all tests...
call :unit
call :integration
call :e2e
echo [INFO] All tests completed!
goto end
:usage
echo Usage: %~nx0 {unit^|integration^|e2e^|ci^|all}
exit /b 1
:end
endlocal

View File

@@ -0,0 +1,95 @@
#!/bin/bash
# Sub2API Test Runner Script
#
# Usage:
# ./run-tests.sh # Run all tests
# ./run-tests.sh unit # Run only unit tests
# ./run-tests.sh e2e # Run only E2E tests
# ./run-tests.sh ci # Run tests in CI mode
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
run_unit_tests() {
log_info "Running backend unit tests..."
cd "$PROJECT_ROOT/backend"
go test -short ./...
log_info "Unit tests completed!"
}
run_integration_tests() {
log_info "Running frontend integration tests..."
cd "$PROJECT_ROOT/frontend"
pnpm test -- --run
log_info "Integration tests completed!"
}
run_e2e_tests() {
log_info "Running E2E tests..."
cd "$SCRIPT_DIR"
npx playwright test
log_info "E2E tests completed!"
}
run_all_tests() {
log_info "Running all tests..."
run_unit_tests
run_integration_tests
run_e2e_tests
log_info "All tests completed!"
}
run_ci_tests() {
log_info "Running CI tests (without E2E)..."
run_unit_tests
run_integration_tests
log_info "CI tests completed!"
}
# Main
case "${1:-all}" in
unit)
run_unit_tests
;;
integration)
run_integration_tests
;;
e2e)
run_e2e_tests
;;
ci)
run_ci_tests
;;
all)
run_all_tests
;;
*)
echo "Usage: $0 {unit|integration|e2e|ci|all}"
exit 1
;;
esac