This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
collector_test.go
84 lines (66 loc) · 1.47 KB
/
collector_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
82
83
84
package bgpls
import (
"net"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCollector(t *testing.T) {
collectorConfig := &CollectorConfig{
ASN: 1234,
RouterID: net.ParseIP("172.16.1.106"),
EventBufferSize: 1024,
}
c, err := NewCollector(collectorConfig)
if err != nil {
t.Fatal(err)
}
d := c.Config()
assert.Equal(t, d, collectorConfig)
neighborConfig := &NeighborConfig{
Address: net.ParseIP("127.0.0.1"),
ASN: 1234,
HoldTime: time.Second * 30,
}
err = c.AddNeighbor(neighborConfig)
if err != nil {
t.Fatal(err)
}
err = c.AddNeighbor(neighborConfig)
assert.NotNil(t, err)
_, err = c.Events()
if err != nil {
t.Fatal(err)
}
neighbors, err := c.Neighbors()
if err != nil {
t.Fatal(err)
}
assert.Len(t, neighbors, 1)
assert.Equal(t, neighbors[0], neighborConfig)
err = c.DeleteNeighbor(net.ParseIP("127.0.0.1"))
if err != nil {
t.Fatal(err)
}
err = c.DeleteNeighbor(net.ParseIP("127.0.0.2"))
assert.NotNil(t, err)
c.Stop()
_, err = c.Events()
assert.Equal(t, err, ErrCollectorStopped)
err = c.AddNeighbor(neighborConfig)
assert.Equal(t, err, ErrCollectorStopped)
_, err = c.Neighbors()
assert.Equal(t, err, ErrCollectorStopped)
err = c.DeleteNeighbor(net.ParseIP("127.0.0.2"))
assert.Equal(t, err, ErrCollectorStopped)
c, err = NewCollector(collectorConfig)
if err != nil {
t.Fatal(err)
}
err = c.AddNeighbor(neighborConfig)
if err != nil {
t.Fatal(err)
}
c.Stop()
c.Stop()
}