forked from kellymusk/Aframp-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.ps1
More file actions
163 lines (140 loc) · 5 KB
/
run_tests.ps1
File metadata and controls
163 lines (140 loc) · 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
# Service Authentication Test Runner (PowerShell)
# This script sets up the test environment and runs all tests
$ErrorActionPreference = "Stop"
Write-Host "=== Service Authentication Test Runner ===" -ForegroundColor Cyan
Write-Host ""
# Check if Rust is installed
try {
$rustVersion = cargo --version
Write-Host "✓ Rust found: $rustVersion" -ForegroundColor Green
} catch {
Write-Host "Error: Rust/Cargo not found" -ForegroundColor Red
Write-Host "Please install Rust from https://rustup.rs/"
exit 1
}
# Check if PostgreSQL is available
$skipDbTests = $false
try {
$null = Get-Command psql -ErrorAction Stop
Write-Host "✓ PostgreSQL client found" -ForegroundColor Green
} catch {
Write-Host "Warning: PostgreSQL client not found" -ForegroundColor Yellow
Write-Host "Tests requiring database will be skipped"
$skipDbTests = $true
}
# Check if Redis is available
$skipRedisTests = $false
try {
$null = Get-Command redis-cli -ErrorAction Stop
# Check if Redis is running
$redisPing = redis-cli ping 2>$null
if ($redisPing -eq "PONG") {
Write-Host "✓ Redis is running" -ForegroundColor Green
} else {
Write-Host "Warning: Redis is not running" -ForegroundColor Yellow
$skipRedisTests = $true
}
} catch {
Write-Host "Warning: Redis client not found" -ForegroundColor Yellow
$skipRedisTests = $true
}
Write-Host ""
Write-Host "=== Running Tests ===" -ForegroundColor Cyan
Write-Host ""
# Run compilation check
Write-Host "1. Checking compilation..."
try {
cargo check --features database 2>&1 | Tee-Object -FilePath "$env:TEMP\cargo_check.log"
Write-Host "✓ Compilation successful" -ForegroundColor Green
} catch {
Write-Host "✗ Compilation failed" -ForegroundColor Red
Write-Host "See $env:TEMP\cargo_check.log for details"
exit 1
}
Write-Host ""
# Run unit tests
Write-Host "2. Running unit tests..."
try {
cargo test service_auth::tests --features database -- --nocapture
Write-Host "✓ Unit tests passed" -ForegroundColor Green
} catch {
Write-Host "✗ Unit tests failed" -ForegroundColor Red
exit 1
}
Write-Host ""
# Run integration tests (if database and Redis are available)
if (-not $skipDbTests -and -not $skipRedisTests) {
Write-Host "3. Running integration tests..."
# Set up environment variables
if (-not $env:DATABASE_URL) {
$env:DATABASE_URL = "postgres://localhost/aframp_test"
Write-Host "Using default DATABASE_URL: $env:DATABASE_URL"
}
if (-not $env:REDIS_URL) {
$env:REDIS_URL = "redis://127.0.0.1:6379"
Write-Host "Using default REDIS_URL: $env:REDIS_URL"
}
# Check if test database exists
$dbExists = psql -lqt | Select-String "aframp_test"
if (-not $dbExists) {
Write-Host "Creating test database..."
try {
createdb aframp_test
} catch {
Write-Host "Warning: Could not create test database" -ForegroundColor Yellow
}
} else {
Write-Host "Test database exists"
}
# Run migrations
Write-Host "Running migrations..."
try {
sqlx migrate run --database-url $env:DATABASE_URL
Write-Host "✓ Migrations applied" -ForegroundColor Green
} catch {
Write-Host "Warning: Migration failed, continuing anyway" -ForegroundColor Yellow
}
# Run integration tests
try {
cargo test --test service_auth_test --features database -- --ignored --nocapture
Write-Host "✓ Integration tests passed" -ForegroundColor Green
} catch {
Write-Host "✗ Integration tests failed" -ForegroundColor Red
exit 1
}
} else {
Write-Host "3. Skipping integration tests (database or Redis not available)"
}
Write-Host ""
Write-Host "=== Test Summary ===" -ForegroundColor Cyan
Write-Host ""
# Get test results
$unitTestOutput = cargo test service_auth::tests --features database 2>&1 | Select-String "test result:"
Write-Host "Unit tests: $unitTestOutput"
if (-not $skipDbTests -and -not $skipRedisTests) {
$integrationTestOutput = cargo test --test service_auth_test --features database -- --ignored 2>&1 | Select-String "test result:"
Write-Host "Integration tests: $integrationTestOutput"
}
Write-Host ""
Write-Host "=== All Tests Completed Successfully ===" -ForegroundColor Green
Write-Host ""
# Optional: Run clippy for linting
try {
$null = Get-Command cargo-clippy -ErrorAction Stop
Write-Host "Running clippy linter..."
cargo clippy --features database -- -D warnings
Write-Host "✓ Clippy checks passed" -ForegroundColor Green
} catch {
# Clippy not installed, skip
}
# Optional: Check formatting
Write-Host "Checking code formatting..."
$formatCheck = cargo fmt -- --check 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "✓ Code formatting is correct" -ForegroundColor Green
} else {
Write-Host "Warning: Code formatting issues found" -ForegroundColor Yellow
Write-Host "Run 'cargo fmt' to fix"
}
Write-Host ""
Write-Host "Test run complete!" -ForegroundColor Cyan