2020-09-26 20:23:43 +02:00
|
|
|
package client
|
|
|
|
|
2020-10-05 01:49:02 +02:00
|
|
|
import (
|
|
|
|
"testing"
|
2021-01-13 03:26:28 +01:00
|
|
|
"time"
|
2020-10-05 01:49:02 +02:00
|
|
|
)
|
2020-09-26 20:23:43 +02:00
|
|
|
|
2020-12-28 23:19:41 +01:00
|
|
|
func TestGetHTTPClient(t *testing.T) {
|
2020-10-23 22:29:20 +02:00
|
|
|
if secureHTTPClient != nil {
|
|
|
|
t.Error("secureHTTPClient should've been nil since it hasn't been called a single time yet")
|
2020-09-26 20:23:43 +02:00
|
|
|
}
|
2020-10-23 22:29:20 +02:00
|
|
|
if insecureHTTPClient != nil {
|
|
|
|
t.Error("insecureHTTPClient should've been nil since it hasn't been called a single time yet")
|
2020-10-04 23:01:10 +02:00
|
|
|
}
|
2020-10-23 22:29:20 +02:00
|
|
|
_ = GetHTTPClient(false)
|
|
|
|
if secureHTTPClient == nil {
|
|
|
|
t.Error("secureHTTPClient shouldn't have been nil, since it has been called once")
|
2020-10-04 23:01:10 +02:00
|
|
|
}
|
2020-10-23 22:29:20 +02:00
|
|
|
if insecureHTTPClient != nil {
|
|
|
|
t.Error("insecureHTTPClient should've been nil since it hasn't been called a single time yet")
|
2020-10-04 23:01:10 +02:00
|
|
|
}
|
2020-10-23 22:29:20 +02:00
|
|
|
_ = GetHTTPClient(true)
|
|
|
|
if secureHTTPClient == nil {
|
|
|
|
t.Error("secureHTTPClient shouldn't have been nil, since it has been called once")
|
2020-10-04 23:01:10 +02:00
|
|
|
}
|
2020-10-23 22:29:20 +02:00
|
|
|
if insecureHTTPClient == nil {
|
|
|
|
t.Error("insecureHTTPClient shouldn't have been nil, since it has been called once")
|
2020-09-26 20:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
2020-12-25 06:07:18 +01:00
|
|
|
|
2020-12-27 23:07:50 +01:00
|
|
|
func TestPing(t *testing.T) {
|
2021-01-13 04:19:19 +01:00
|
|
|
pingTimeout = 500 * time.Millisecond
|
2020-12-27 23:07:50 +01:00
|
|
|
if success, rtt := Ping("127.0.0.1"); !success {
|
2020-12-25 06:07:18 +01:00
|
|
|
t.Error("expected true")
|
2020-12-27 23:07:50 +01:00
|
|
|
if rtt == 0 {
|
|
|
|
t.Error("Round-trip time returned on success should've higher than 0")
|
|
|
|
}
|
2020-12-25 06:07:18 +01:00
|
|
|
}
|
2020-12-27 23:07:50 +01:00
|
|
|
if success, rtt := Ping("256.256.256.256"); success {
|
2021-01-13 03:26:28 +01:00
|
|
|
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")
|
2020-12-27 23:07:50 +01:00
|
|
|
if rtt != 0 {
|
|
|
|
t.Error("Round-trip time returned on failure should've been 0")
|
|
|
|
}
|
2020-12-25 06:07:18 +01:00
|
|
|
}
|
|
|
|
}
|