-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.ps1
More file actions
64 lines (52 loc) · 2.28 KB
/
Copy pathtest-server.ps1
File metadata and controls
64 lines (52 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Test script to run the Go server and test all endpoints
Write-Host "Testing Go installation..." -ForegroundColor Cyan
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
go version
if ($LASTEXITCODE -ne 0) {
Write-Host "Go is not found in PATH. Please restart PowerShell or run:" -ForegroundColor Red
Write-Host '$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")' -ForegroundColor Yellow
exit 1
}
Write-Host "`nStarting the server in background..." -ForegroundColor Cyan
$job = Start-Job -ScriptBlock {
Set-Location "C:\Users\shres\OneDrive\Desktop\Dev\microadserve-go"
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
go run .
}
Write-Host "Waiting for server to start..." -ForegroundColor Cyan
Start-Sleep -Seconds 3
Write-Host "`n=== Testing Endpoints ===" -ForegroundColor Green
Write-Host "`n1. GET /health" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "http://localhost:8080/health" -Method Get
$response | ConvertTo-Json
} catch {
Write-Host "Error: $_" -ForegroundColor Red
}
Write-Host "`n2. GET /ad" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "http://localhost:8080/ad" -Method Get
$response | ConvertTo-Json
} catch {
Write-Host "Error: $_" -ForegroundColor Red
}
Write-Host "`n3. POST /impression" -ForegroundColor Yellow
try {
$body = @{ ad_id = "ad_2" } | ConvertTo-Json
$response = Invoke-RestMethod -Uri "http://localhost:8080/impression" -Method Post -Body $body -ContentType "application/json"
$response | ConvertTo-Json
} catch {
Write-Host "Error: $_" -ForegroundColor Red
}
Write-Host "`n4. GET /metrics" -ForegroundColor Yellow
try {
$response = Invoke-RestMethod -Uri "http://localhost:8080/metrics" -Method Get
$response | ConvertTo-Json -Depth 10
} catch {
Write-Host "Error: $_" -ForegroundColor Red
}
Write-Host "`n=== Test Complete ===" -ForegroundColor Green
Write-Host "`nStopping server..." -ForegroundColor Cyan
Stop-Job -Job $job
Remove-Job -Job $job
Write-Host "Done!" -ForegroundColor Green