Files
wwjcloud/wwjcloud/test-config-center.ps1
万物街 2084711030 feat: 完成配置中心重构和命名规范优化
- 重构config层为配置中心架构,支持动态配置管理
- 统一core层命名规范(event-bus→event, circuit-breaker→breaker, domain-sdk→sdk)
- 修复数据库连接配置路径问题
- 实现配置中心完整功能:系统配置、动态配置、配置验证、统计
- 优化目录结构,为微服务架构做准备
- 修复TypeScript编译错误和依赖注入问题
2025-08-28 05:19:14 +08:00

102 lines
4.5 KiB
PowerShell

# 配置中心测试脚本
Write-Host "=== 配置中心功能测试 ===" -ForegroundColor Green
# 1. 登录获取令牌
Write-Host "1. 登录获取令牌..." -ForegroundColor Yellow
$loginBody = @{
username = "admin"
password = "123456"
} | ConvertTo-Json
try {
$loginResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/auth/login" -Method POST -ContentType "application/json" -Body $loginBody
$loginData = $loginResponse.Content | ConvertFrom-Json
if ($loginData.token) {
$token = $loginData.token
Write-Host "✓ 登录成功,获取到令牌" -ForegroundColor Green
# 2. 测试系统配置接口
Write-Host "`n2. 测试系统配置接口..." -ForegroundColor Yellow
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
try {
$systemConfigResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/config/system" -Method GET -Headers $headers
$systemConfig = $systemConfigResponse.Content | ConvertFrom-Json
Write-Host "✓ 系统配置获取成功" -ForegroundColor Green
Write-Host "配置内容: $($systemConfig | ConvertTo-Json -Depth 2)" -ForegroundColor Cyan
}
catch {
Write-Host "✗ 系统配置获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
# 3. 测试动态配置列表
Write-Host "`n3. 测试动态配置列表..." -ForegroundColor Yellow
try {
$dynamicConfigResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/config/dynamic" -Method GET -Headers $headers
$dynamicConfig = $dynamicConfigResponse.Content | ConvertFrom-Json
Write-Host "✓ 动态配置列表获取成功" -ForegroundColor Green
Write-Host "动态配置: $($dynamicConfig | ConvertTo-Json)" -ForegroundColor Cyan
}
catch {
Write-Host "✗ 动态配置列表获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
# 4. 测试配置验证
Write-Host "`n4. 测试配置验证..." -ForegroundColor Yellow
try {
$validateResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/config/validate" -Method GET -Headers $headers
$validateResult = $validateResponse.Content | ConvertFrom-Json
Write-Host "✓ 配置验证成功" -ForegroundColor Green
Write-Host "验证结果: $($validateResult | ConvertTo-Json)" -ForegroundColor Cyan
}
catch {
Write-Host "✗ 配置验证失败: $($_.Exception.Message)" -ForegroundColor Red
}
# 5. 测试配置统计
Write-Host "`n5. 测试配置统计..." -ForegroundColor Yellow
try {
$statsResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/config/stats" -Method GET -Headers $headers
$stats = $statsResponse.Content | ConvertFrom-Json
Write-Host "✓ 配置统计获取成功" -ForegroundColor Green
Write-Host "统计信息: $($stats | ConvertTo-Json)" -ForegroundColor Cyan
}
catch {
Write-Host "✗ 配置统计获取失败: $($_.Exception.Message)" -ForegroundColor Red
}
# 6. 测试创建动态配置
Write-Host "`n6. 测试创建动态配置..." -ForegroundColor Yellow
$newConfigBody = @{
key = "test.feature.flag"
value = $true
description = "测试功能开关"
type = "boolean"
category = "test"
isPublic = $true
} | ConvertTo-Json
try {
$createResponse = Invoke-WebRequest -Uri "http://localhost:3000/adminapi/config/dynamic" -Method POST -Headers $headers -Body $newConfigBody
$createResult = $createResponse.Content | ConvertFrom-Json
Write-Host "✓ 动态配置创建成功" -ForegroundColor Green
Write-Host "创建结果: $($createResult | ConvertTo-Json)" -ForegroundColor Cyan
}
catch {
Write-Host "✗ 动态配置创建失败: $($_.Exception.Message)" -ForegroundColor Red
}
} else {
Write-Host "✗ 登录失败,未获取到令牌" -ForegroundColor Red
}
}
catch {
Write-Host "✗ 登录请求失败: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host "`n=== 测试完成 ===" -ForegroundColor Green