1
0
Fork 0
mirror of https://github.com/TwiN/gatus.git synced 2024-12-15 17:51:09 +00:00

Improve test coverage

This commit is contained in:
TwinProduction 2021-01-12 21:26:28 -05:00
parent aec867ae69
commit 26d8870cab
2 changed files with 12 additions and 2 deletions

View file

@ -12,6 +12,8 @@ import (
var (
secureHTTPClient *http.Client
insecureHTTPClient *http.Client
pingTimeout = 5 * time.Second
)
// GetHTTPClient returns the shared HTTP client
@ -62,7 +64,7 @@ func Ping(address string) (bool, time.Duration) {
return false, 0
}
pinger.Count = 1
pinger.Timeout = 5 * time.Second
pinger.Timeout = pingTimeout
pinger.SetNetwork("ip4")
pinger.SetPrivileged(true)
err = pinger.Run()

View file

@ -2,6 +2,7 @@ package client
import (
"testing"
"time"
)
func TestGetHTTPClient(t *testing.T) {
@ -28,6 +29,7 @@ func TestGetHTTPClient(t *testing.T) {
}
func TestPing(t *testing.T) {
pingTimeout = time.Second
if success, rtt := Ping("127.0.0.1"); !success {
t.Error("expected true")
if rtt == 0 {
@ -35,7 +37,13 @@ func TestPing(t *testing.T) {
}
}
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 {
t.Error("Round-trip time returned on failure should've been 0")
}