mirror of
https://github.com/unpoller/unpoller.git
synced 2026-09-29 19:11:17 +02:00
fix(promunifi): accept a bracketed IPv6 http_listen in the health check
This commit is contained in:
@@ -240,9 +240,8 @@ func (u *promUnifi) DebugOutput() (bool, error) {
|
||||
}
|
||||
|
||||
// check the port
|
||||
parts := strings.Split(u.HTTPListen, ":")
|
||||
if len(parts) != 2 {
|
||||
return false, fmt.Errorf("invalid listen address: %s (must be of the form \"IP:Port\"", u.HTTPListen)
|
||||
if _, _, err := net.SplitHostPort(u.HTTPListen); err != nil {
|
||||
return false, fmt.Errorf("invalid listen address: %s (must be of the form \"IP:Port\")", u.HTTPListen)
|
||||
}
|
||||
|
||||
// Skip network binding check during health checks to avoid "address already in use"
|
||||
|
||||
@@ -20,3 +20,32 @@ func TestDebugOutputAcceptsUnsetHTTPListen(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, defaultHTTPListen, u.HTTPListen)
|
||||
}
|
||||
|
||||
func TestDebugOutputAcceptsAnIPv6HTTPListen(t *testing.T) {
|
||||
poller.SetHealthCheckMode(true)
|
||||
t.Cleanup(func() { poller.SetHealthCheckMode(false) })
|
||||
|
||||
tests := []struct {
|
||||
listen string
|
||||
valid bool
|
||||
}{
|
||||
{"0.0.0.0:9130", true},
|
||||
{"[::]:9130", true},
|
||||
{":9130", true},
|
||||
{"0.0.0.0", false},
|
||||
{"0.0.0.0:9130:9131", false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
u := &promUnifi{Config: &Config{HTTPListen: test.listen}}
|
||||
|
||||
ok, err := u.DebugOutput()
|
||||
assert.Equal(t, test.valid, ok, test.listen)
|
||||
|
||||
if test.valid {
|
||||
require.NoError(t, err, test.listen)
|
||||
} else {
|
||||
require.Error(t, err, test.listen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user