# 测试权限端点 Write-Host "🔍 测试权限端点..." -ForegroundColor Yellow # 启动后端服务 Write-Host "🚀 启动后端服务..." -ForegroundColor Green Start-Process -FilePath "go" -ArgumentList "run", "main.go" -WorkingDirectory "backend" -WindowStyle Hidden # 等待服务启动 Write-Host "⏳ 等待服务启动..." -ForegroundColor Yellow Start-Sleep -Seconds 5 try { # 测试权限端点 Write-Host "🔍 测试 /api/auth/permissions 端点..." -ForegroundColor Cyan $response = Invoke-RestMethod -Uri "http://localhost:8080/api/auth/permissions" -Method GET -ErrorAction Stop Write-Host "✅ 权限端点响应:" -ForegroundColor Green $response | ConvertTo-Json -Depth 3 } catch { Write-Host "❌ 权限端点测试失败:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red # 测试其他端点 Write-Host "🔍 测试 /api/auth/roles 端点..." -ForegroundColor Cyan try { $response = Invoke-RestMethod -Uri "http://localhost:8080/api/auth/roles" -Method GET -ErrorAction Stop Write-Host "✅ 角色端点响应:" -ForegroundColor Green $response | ConvertTo-Json -Depth 3 } catch { Write-Host "❌ 角色端点也失败:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red } # 测试健康检查端点 Write-Host "🔍 测试 /health 端点..." -ForegroundColor Cyan try { $response = Invoke-RestMethod -Uri "http://localhost:8080/health" -Method GET -ErrorAction Stop Write-Host "✅ 健康检查端点响应:" -ForegroundColor Green $response | ConvertTo-Json -Depth 3 } catch { Write-Host "❌ 健康检查端点也失败:" -ForegroundColor Red Write-Host $_.Exception.Message -ForegroundColor Red } } finally { # 停止后端服务 Write-Host "🛑 停止后端服务..." -ForegroundColor Yellow Get-Process -Name "go" -ErrorAction SilentlyContinue | Stop-Process -Force } Write-Host "✅ 测试完成" -ForegroundColor Green