-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-integration.ps1
More file actions
272 lines (230 loc) · 10.5 KB
/
Copy pathtest-integration.ps1
File metadata and controls
272 lines (230 loc) · 10.5 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Integration Testing Script
# Tests Frontend ↔ Backend ↔ Database connectivity
Write-Host "========================================" -ForegroundColor Green
Write-Host "INTEGRATION TEST SUITE" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host "`nStarted at: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`n" -ForegroundColor Yellow
$testsPassed = 0
$testsFailed = 0
function Test-Endpoint {
param(
[string]$Name,
[string]$Method,
[string]$Url,
[hashtable]$Headers = @{},
[string]$Body = $null
)
Write-Host "Testing: $Name" -ForegroundColor Cyan -NoNewline
try {
$params = @{
Uri = $Url
Method = $Method
Headers = $Headers
TimeoutSec = 10
ErrorAction = "Stop"
UseBasicParsing = $true
}
if ($Body) {
$params['Body'] = $Body
$params['ContentType'] = 'application/json'
}
$response = Invoke-WebRequest @params
Write-Host " ✓ PASSED" -ForegroundColor Green
Write-Host " Status: $($response.StatusCode)" -ForegroundColor Gray
$testsPassed++
return $response
} catch {
Write-Host " ✗ FAILED" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
$testsFailed++
return $null
}
}
function Test-DockerContainer {
param(
[string]$ContainerName
)
Write-Host "Checking container: $ContainerName" -ForegroundColor Cyan -NoNewline
try {
$status = docker-compose ps $ContainerName --format='{{.State}}'
if ($status -eq 'Up') {
Write-Host " ✓ RUNNING" -ForegroundColor Green
$testsPassed++
return $true
} else {
Write-Host " ✗ NOT RUNNING" -ForegroundColor Red
Write-Host " State: $status" -ForegroundColor Red
$testsFailed++
return $false
}
} catch {
Write-Host " ✗ ERROR" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
$testsFailed++
return $false
}
}
# ============================================
# SECTION 1: Docker Containers
# ============================================
Write-Host "`n[1] DOCKER CONTAINERS" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Test-DockerContainer "tnp-nginx" | Out-Null
Test-DockerContainer "tnp-backend" | Out-Null
Test-DockerContainer "tnp-frontend" | Out-Null
Test-DockerContainer "tnp-postgres" | Out-Null
Test-DockerContainer "tnp-redis" | Out-Null
# ============================================
# SECTION 2: Backend Health
# ============================================
Write-Host "`n[2] BACKEND HEALTH CHECKS" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
$healthResponse = Test-Endpoint -Name "Backend Health" -Method "GET" -Url "http://localhost:3000/health"
$infoResponse = Test-Endpoint -Name "Backend Info" -Method "GET" -Url "http://localhost:3000/info"
# ============================================
# SECTION 3: Frontend Access
# ============================================
Write-Host "`n[3] FRONTEND ACCESS" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Test-Endpoint -Name "Frontend (via Nginx)" -Method "GET" -Url "http://localhost/" | Out-Null
# ============================================
# SECTION 4: CORS Headers
# ============================================
Write-Host "`n[4] CORS CONFIGURATION" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Write-Host "Checking CORS headers..." -ForegroundColor Cyan -NoNewline
try {
$corsTest = Invoke-WebRequest `
-Uri "http://localhost:3000/health" `
-Method "OPTIONS" `
-Headers @{"Origin" = "http://localhost:5173"} `
-TimeoutSec 10 `
-UseBasicParsing
$corsHeader = $corsTest.Headers['Access-Control-Allow-Origin']
if ($corsHeader) {
Write-Host " ✓ ENABLED" -ForegroundColor Green
Write-Host " CORS Origin: $corsHeader" -ForegroundColor Gray
$testsPassed++
} else {
Write-Host " ⚠ WARNING" -ForegroundColor Yellow
Write-Host " No CORS headers found" -ForegroundColor Yellow
}
} catch {
Write-Host " ⚠ WARNING" -ForegroundColor Yellow
Write-Host " Could not verify CORS: $($_.Exception.Message)" -ForegroundColor Yellow
}
# ============================================
# SECTION 5: Database Connection
# ============================================
Write-Host "`n[5] DATABASE CONNECTION" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Write-Host "Checking PostgreSQL connection..." -ForegroundColor Cyan -NoNewline
try {
$connectionString = "Server=localhost;Port=5432;User Id=neondb_owner;Password=postgres;Database=neondb;"
# Try to connect using docker
$psqlTest = docker-compose exec -T postgres pg_isready -U neondb_owner -h localhost
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ CONNECTED" -ForegroundColor Green
$testsPassed++
} else {
Write-Host " ✗ FAILED" -ForegroundColor Red
$testsFailed++
}
} catch {
Write-Host " ⚠ WARNING" -ForegroundColor Yellow
Write-Host " PostgreSQL check skipped" -ForegroundColor Yellow
}
# ============================================
# SECTION 6: Redis Connection
# ============================================
Write-Host "`n[6] REDIS CONNECTION" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Write-Host "Checking Redis connection..." -ForegroundColor Cyan -NoNewline
try {
$redisTest = docker-compose exec -T redis redis-cli ping
if ($redisTest -eq "PONG") {
Write-Host " ✓ CONNECTED" -ForegroundColor Green
Write-Host " Response: $redisTest" -ForegroundColor Gray
$testsPassed++
} else {
Write-Host " ✗ FAILED" -ForegroundColor Red
$testsFailed++
}
} catch {
Write-Host " ⚠ WARNING" -ForegroundColor Yellow
Write-Host " Redis check skipped: $($_.Exception.Message)" -ForegroundColor Yellow
}
# ============================================
# SECTION 7: Port Availability
# ============================================
Write-Host "`n[7] PORT AVAILABILITY" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
$ports = @{
"3000" = "Backend API"
"5173" = "Frontend Dev"
"5432" = "PostgreSQL"
"6379" = "Redis"
"80" = "Nginx HTTP"
"443" = "Nginx HTTPS"
}
foreach ($port in $ports.GetEnumerator()) {
Write-Host "Port $($port.Key) ($($port.Value)):" -ForegroundColor Cyan -NoNewline
$tcpTest = Test-NetConnection -ComputerName "localhost" -Port $port.Key -WarningAction SilentlyContinue
if ($tcpTest.TcpTestSucceeded) {
Write-Host " ✓ OPEN" -ForegroundColor Green
$testsPassed++
} else {
Write-Host " ✗ CLOSED" -ForegroundColor Red
$testsFailed++
}
}
# ============================================
# SECTION 8: API Endpoint Tests
# ============================================
Write-Host "`n[8] API ENDPOINTS" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Test-Endpoint -Name "GET /api/v1/auth/health" -Method "GET" -Url "http://localhost:3000/api/v1/auth/health" | Out-Null
# ============================================
# SECTION 9: Backend Logs
# ============================================
Write-Host "`n[9] RECENT BACKEND LOGS" -ForegroundColor Magenta
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Magenta
Write-Host "Last 10 backend log lines:" -ForegroundColor Cyan
try {
$logs = docker-compose logs --tail=10 backend
Write-Host $logs -ForegroundColor Gray
} catch {
Write-Host "Could not retrieve logs" -ForegroundColor Yellow
}
# ============================================
# SUMMARY
# ============================================
Write-Host "`n========================================" -ForegroundColor Green
Write-Host "TEST SUMMARY" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host "`nTests Passed: " -NoNewline
Write-Host "$testsPassed" -ForegroundColor Green -NoNewline
Write-Host " ✓"
Write-Host "Tests Failed: " -NoNewline
Write-Host "$testsFailed" -ForegroundColor Red -NoNewline
Write-Host " ✗"
$totalTests = $testsPassed + $testsFailed
Write-Host "Total Tests: $totalTests"
if ($testsFailed -eq 0) {
Write-Host "`n✅ ALL TESTS PASSED!" -ForegroundColor Green
Write-Host "`nYour integration is working correctly:" -ForegroundColor Green
Write-Host "• Frontend can communicate with Backend" -ForegroundColor Green
Write-Host "• Backend can connect to Database" -ForegroundColor Green
Write-Host "• Backend can connect to Redis" -ForegroundColor Green
Write-Host "• All services are healthy" -ForegroundColor Green
} else {
Write-Host "`n❌ SOME TESTS FAILED" -ForegroundColor Red
Write-Host "`nPlease review the failures above and check:" -ForegroundColor Yellow
Write-Host "• Docker containers are running: docker-compose ps" -ForegroundColor Yellow
Write-Host "• No port conflicts: netstat -ano | findstr :PORT" -ForegroundColor Yellow
Write-Host "• Backend logs: docker-compose logs backend" -ForegroundColor Yellow
Write-Host "• Database logs: docker-compose logs postgres" -ForegroundColor Yellow
}
Write-Host "`nCompleted at: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor Yellow
Write-Host "`n========================================`n" -ForegroundColor Green
Read-Host "Press Enter to exit"