-
Notifications
You must be signed in to change notification settings - Fork 2
/
ntp_test.go
58 lines (49 loc) · 1.45 KB
/
ntp_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var reachablePools = []string{
"0.coreos.pool.ntp.org",
"1.coreos.pool.ntp.org",
"2.coreos.pool.ntp.org",
"3.coreos.pool.ntp.org",
"0.pool.ntp.org",
"2.pool.ntp.org",
}
var someReachablePools = []string{
"foobar8237.ntp.org",
"0.coreos.pool.ntp.org",
"1.pool.ntp.org",
"foobarlllx237.ntp.org",
"3.pool.ntp.org",
}
var unreachablePools = []string{
"foobar8237.ntp.org",
"foobarlllx237.ntp.org",
}
func TestCallNtpWithPoolsAllPoolsReachable(t *testing.T) {
ntpc := &ntpCheckerImpl{
timeDrift: time.Second,
}
result, err := ntpc.callNtpWithPools(reachablePools)
assert.Nil(t, err, "Error should be nil when all pools are reachable")
assert.NotNil(t, result, "Result should not be nil when all pools are reachable")
}
func TestCallNtpWithPoolsSomePoolsReachable(t *testing.T) {
ntpc := &ntpCheckerImpl{
timeDrift: time.Second,
}
result, err := ntpc.callNtpWithPools(someReachablePools)
assert.Nil(t, err, "Error should be nil when some pools are reachable")
assert.NotNil(t, result, "Result should not be nil when some pools are reachable")
}
func TestCallNtpWithPoolsAllPoolsUnreachable(t *testing.T) {
ntpc := &ntpCheckerImpl{
timeDrift: time.Second,
}
result, err := ntpc.callNtpWithPools(unreachablePools)
assert.NotNil(t, err, "Error should not be nil when all pools are unreachable")
assert.Nil(t, result, "Result should be nil when all pools are unreachable")
}