forked from dropbox/llama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testrunner_test.go
81 lines (73 loc) · 2.06 KB
/
testrunner_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package llama
import (
"golang.org/x/time/rate"
"net"
"testing"
)
var exampleCallbackChan = make(chan *Probe)
func TestTestRunnerRun(t *testing.T) {
// TODO(dmar): A more intensive test of this requires more mocking.
// For now, it's at least touched in `TestTestRunnerStop`.
}
func TestTestRunnerStop(t *testing.T) {
tr := NewTestRunner(exampleCallbackChan, rate.NewLimiter(rate.Inf, 0))
tr.Run()
tr.Stop()
if tr.isStopped() != true {
t.Error("Stopped the TestRunner, but it didn't stop")
}
}
func TestAddAndDel(t *testing.T) {
tr := NewTestRunner(exampleCallbackChan, rate.NewLimiter(rate.Inf, 0))
target, err := net.ResolveUDPAddr("udp", DefaultAddrStr)
HandleError(err)
if len(tr.targets) != 0 {
t.Error("TestRunner already has targets, but shouldn't")
}
// Validate adding a target
tr.Add(target)
if len(tr.targets) != 1 {
t.Error("TestRunner should only have one target")
}
if tr.targets[0] != target {
t.Error("Target in TestRunner isn't the one we added")
}
// Now validate deletion
tr.Del(target)
if len(tr.targets) != 0 {
t.Error("TestRunner didn't delete the target")
}
}
func TestSet(t *testing.T) {
tr := NewTestRunner(exampleCallbackChan, rate.NewLimiter(rate.Inf, 0))
target, err := net.ResolveUDPAddr("udp", DefaultAddrStr)
HandleError(err)
targets := []*net.UDPAddr{target, target, target}
tr.Set(targets)
if len(tr.targets) != len(targets) {
t.Error("Set targets, but TestRunner len doesn't match")
}
for k := range tr.targets {
if tr.targets[k] != targets[k] {
t.Error("Set targets, but TestRunner contents don't match")
}
}
}
func TestAddNewPort(t *testing.T) {
// This is all generally tested as part of PortGroup already
tr := NewTestRunner(exampleCallbackChan, rate.NewLimiter(rate.Inf, 0))
tr.AddNewPort(
DefaultAddrStr,
DefaultTos,
DefaultCacheTimeout,
DefaultCacheCleanRate,
DefaultReadTimeout,
)
}
func TestNewTestRunner(t *testing.T) {
// Just test creating one
tr := NewTestRunner(exampleCallbackChan, rate.NewLimiter(rate.Inf, 0))
if tr == nil {
t.Error("New failed to create a TestRunner")
}
}