-
Notifications
You must be signed in to change notification settings - Fork 314
/
test_health_check_output_of_http_gateway.ps1
55 lines (46 loc) · 2.15 KB
/
test_health_check_output_of_http_gateway.ps1
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
if ($IsWindows) {
$test_probe_release="habitat-testing/test-probe/0.1.0/20230620183252"
} else {
$test_probe_release="habitat-testing/test-probe/0.1.0/20230621013852"
}
Describe "HTTP gateway" {
AfterAll {
Unload-SupervisorService -PackageName habitat-testing/test-probe -Timeout 30
Stop-Supervisor
}
$supLog = New-SupervisorLogFile("test_health_check_output_of_http_gateway")
Start-Supervisor -LogFile $supLog -Timeout 45 -SupArgs @( `
"--health-check-interval=10"
) | Out-Null
Load-SupervisorService $test_probe_release
Wait-Release -Ident $test_probe_release
Context "with a service with a health-check hook" {
# test-probe has a long init hook, and we want
# to let the health-check hoo
Start-Sleep 20
It "returns output of the hook when queried" {
$stdout = (Invoke-WebRequest "http://localhost:9631/services/test-probe/default/health" | ConvertFrom-Json).stdout
$stdout | Should -MatchExactly "Running health_check hook: habitat-testing/test-probe"
}
It "returns status of the hook when queried" {
$status = (Invoke-WebRequest "http://localhost:9631/services/test-probe/default/health" | ConvertFrom-Json).status
$status | Should -MatchExactly "OK"
}
It "returns status of the hook from services" {
$status = (Invoke-WebRequest "http://localhost:9631/services" | ConvertFrom-Json)[0].health_check
$status | Should -MatchExactly "Ok"
}
}
Context "with a service that changes status" {
Set-Content -Path "/hab/pkgs/$test_probe_release/health_exit" -Value 1
Start-Sleep 30
It "returns status of the hook when queried" {
$status = (Invoke-WebRequest "http://localhost:9631/services/test-probe/default/health" | ConvertFrom-Json).status
$status | Should -MatchExactly "WARNING"
}
It "returns status of the hook from services" {
$status = (Invoke-WebRequest "http://localhost:9631/services" | ConvertFrom-Json)[0].health_check
$status | Should -MatchExactly "Warning"
}
}
}