-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
39 lines (36 loc) · 1.09 KB
/
Copy pathmain_test.go
File metadata and controls
39 lines (36 loc) · 1.09 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
package main
import "testing"
func TestHealthcheckURL(t *testing.T) {
tests := []struct {
listenAddr string
want string
wantErr bool
}{
// Wildcard binds are probed via loopback.
{listenAddr: ":8080", want: "http://127.0.0.1:8080/healthz"},
{listenAddr: "0.0.0.0:8080", want: "http://127.0.0.1:8080/healthz"},
{listenAddr: "[::]:8080", want: "http://127.0.0.1:8080/healthz"},
// Explicit bind hosts are probed directly.
{listenAddr: "127.0.0.1:9999", want: "http://127.0.0.1:9999/healthz"},
{listenAddr: "somehost:8081", want: "http://somehost:8081/healthz"},
{listenAddr: "8080", wantErr: true},
{listenAddr: "", wantErr: true},
}
for _, tt := range tests {
t.Run(tt.listenAddr, func(t *testing.T) {
got, err := healthcheckURL(tt.listenAddr)
if tt.wantErr {
if err == nil {
t.Fatalf("healthcheckURL(%q) = %q, want error", tt.listenAddr, got)
}
return
}
if err != nil {
t.Fatalf("healthcheckURL(%q): %v", tt.listenAddr, err)
}
if got != tt.want {
t.Errorf("healthcheckURL(%q) = %q, want %q", tt.listenAddr, got, tt.want)
}
})
}
}