mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 23:43:27 +01:00
Improve test coverage
This commit is contained in:
parent
aec867ae69
commit
26d8870cab
@ -12,6 +12,8 @@ import (
|
|||||||
var (
|
var (
|
||||||
secureHTTPClient *http.Client
|
secureHTTPClient *http.Client
|
||||||
insecureHTTPClient *http.Client
|
insecureHTTPClient *http.Client
|
||||||
|
|
||||||
|
pingTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetHTTPClient returns the shared HTTP client
|
// GetHTTPClient returns the shared HTTP client
|
||||||
@ -62,7 +64,7 @@ func Ping(address string) (bool, time.Duration) {
|
|||||||
return false, 0
|
return false, 0
|
||||||
}
|
}
|
||||||
pinger.Count = 1
|
pinger.Count = 1
|
||||||
pinger.Timeout = 5 * time.Second
|
pinger.Timeout = pingTimeout
|
||||||
pinger.SetNetwork("ip4")
|
pinger.SetNetwork("ip4")
|
||||||
pinger.SetPrivileged(true)
|
pinger.SetPrivileged(true)
|
||||||
err = pinger.Run()
|
err = pinger.Run()
|
||||||
|
@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetHTTPClient(t *testing.T) {
|
func TestGetHTTPClient(t *testing.T) {
|
||||||
@ -28,6 +29,7 @@ func TestGetHTTPClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPing(t *testing.T) {
|
func TestPing(t *testing.T) {
|
||||||
|
pingTimeout = time.Second
|
||||||
if success, rtt := Ping("127.0.0.1"); !success {
|
if success, rtt := Ping("127.0.0.1"); !success {
|
||||||
t.Error("expected true")
|
t.Error("expected true")
|
||||||
if rtt == 0 {
|
if rtt == 0 {
|
||||||
@ -35,7 +37,13 @@ func TestPing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if success, rtt := Ping("256.256.256.256"); success {
|
if success, rtt := Ping("256.256.256.256"); success {
|
||||||
t.Error("expected false")
|
t.Error("expected false, because the IP is invalid")
|
||||||
|
if rtt != 0 {
|
||||||
|
t.Error("Round-trip time returned on failure should've been 0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if success, rtt := Ping("192.168.152.153"); success {
|
||||||
|
t.Error("expected false, because the IP is valid but the host should be unreachable")
|
||||||
if rtt != 0 {
|
if rtt != 0 {
|
||||||
t.Error("Round-trip time returned on failure should've been 0")
|
t.Error("Round-trip time returned on failure should've been 0")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user