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
|
package control
import "testing"
func TestParseHealthCheckOutput(t *testing.T) {
t.Parallel()
stdout := `{"Service":"sing-box","State":"running"}
{"Service":"caddy","State":"running"}
HEALTHZ_HTTP_CODE=200
`
services, metadata := parseHealthCheckOutput(stdout, []ProtocolProfile{
{Type: "vless", Enabled: true, Port: 443},
{Type: "vmess", Enabled: true, Port: 443},
{Type: "shadowsocks", Enabled: true, Port: 8443},
})
if len(services) != 3 {
t.Fatalf("len(services) = %d, want 3", len(services))
}
if metadata["healthz_http_code"] != 200 {
t.Fatalf("healthz_http_code = %v, want 200", metadata["healthz_http_code"])
}
if services[0].Status != "running" && services[1].Status != "running" && services[2].Status != "running" {
t.Fatal("expected at least one service marked running")
}
}
func TestParseHealthCheckOutputDockerPSFallback(t *testing.T) {
t.Parallel()
stdout := `{"Names":"current_sing-box_1","Labels":"com.docker.compose.service=sing-box,com.docker.compose.project=current","State":"running","Status":"Up 52 seconds"}
HY2_MIXED_PORT=5.180.97.199
`
services, _ := parseHealthCheckOutput(stdout, []ProtocolProfile{
{Type: "vless-reality", Enabled: true, Port: 443},
{Type: "hysteria2", Enabled: true, Port: 443},
})
if len(services) != 2 {
t.Fatalf("len(services) = %d, want 2", len(services))
}
if services[0].Status != "running" {
t.Fatalf("vless-reality status = %q, want running", services[0].Status)
}
if services[1].Status != "running" {
t.Fatalf("hysteria2 status = %q, want running", services[1].Status)
}
}
|