1
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$workspaceRoot = Split-Path -Parent $PSScriptRoot
|
||||
$apiProjectDirectory = Join-Path $workspaceRoot 'src/Jiaowu.Api'
|
||||
$apiExecutable = Join-Path $workspaceRoot 'src/Jiaowu.Api/bin/Debug/net10.0/Jiaowu.Api.exe'
|
||||
$stdoutPath = Join-Path $env:TEMP 'jiaowu-api-smoke.out.log'
|
||||
$stderrPath = Join-Path $env:TEMP 'jiaowu-api-smoke.err.log'
|
||||
$env:ASPNETCORE_ENVIRONMENT = 'Development'
|
||||
$env:ASPNETCORE_URLS = 'http://localhost:5255'
|
||||
$startParameters = @{
|
||||
FilePath = $apiExecutable
|
||||
WorkingDirectory = $apiProjectDirectory
|
||||
WindowStyle = 'Hidden'
|
||||
RedirectStandardOutput = $stdoutPath
|
||||
RedirectStandardError = $stderrPath
|
||||
PassThru = $true
|
||||
}
|
||||
$process = Start-Process @startParameters
|
||||
|
||||
try {
|
||||
$healthy = $false
|
||||
for ($attempt = 0; $attempt -lt 30; $attempt++) {
|
||||
Start-Sleep -Milliseconds 500
|
||||
try {
|
||||
$health = Invoke-RestMethod -Uri 'http://localhost:5255/health' -TimeoutSec 2
|
||||
$healthy = $true
|
||||
break
|
||||
}
|
||||
catch {
|
||||
# The API may still be starting.
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $healthy) {
|
||||
Get-Content -LiteralPath $stdoutPath -ErrorAction SilentlyContinue
|
||||
Get-Content -LiteralPath $stderrPath -ErrorAction SilentlyContinue
|
||||
throw 'API did not become healthy.'
|
||||
}
|
||||
|
||||
$loginBody = @{
|
||||
userName = 'admin'
|
||||
password = 'Admin@123456'
|
||||
} | ConvertTo-Json
|
||||
$loginParameters = @{
|
||||
Method = 'Post'
|
||||
Uri = 'http://localhost:5255/api/auth/login'
|
||||
ContentType = 'application/json'
|
||||
Body = $loginBody
|
||||
}
|
||||
$login = Invoke-RestMethod @loginParameters
|
||||
$headers = @{ Authorization = "Bearer $($login.token)" }
|
||||
$dashboard = Invoke-RestMethod -Uri 'http://localhost:5255/api/dashboard' -Headers $headers
|
||||
$campuses = Invoke-RestMethod -Uri 'http://localhost:5255/api/base-data/campuses' -Headers $headers
|
||||
|
||||
[pscustomobject]@{
|
||||
Health = $health.status
|
||||
Database = $health.database
|
||||
User = $login.user.displayName
|
||||
Term = $dashboard.currentTerm.name
|
||||
Campuses = @($campuses).Count
|
||||
} | Format-List
|
||||
}
|
||||
finally {
|
||||
if (-not $process.HasExited) {
|
||||
Stop-Process -Id $process.Id -Force
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user