Debian Codegraph @

parser/bfd_test.go

raw symbols SCIP
1 package parser
2
3 import (
4 "testing"
5 "time"
6
7 "github.com/czerwonk/bird_exporter/protocol"
8 "github.com/stretchr/testify/assert"
9 )
10
11 func TestParseBFDSessions(t *testing.T) {
12 overrideNowFunc(func() time.Time {
13 return time.Date(2022, 1, 27, 10, 0, 0, 0, time.Local)
14 })
15
16 data := `BIRD 2.0.7 ready.
17 bfd1:
18 IP address Interface State Since Interval Timeout
19 192.168.64.9 enp0s2 Up 2022-01-27 09:00:00 1697620076 0.100 1.000
20 192.168.64.10 enp0s2 Down 2022-01-27 08:00:00 0.300 0.000
21 192.168.64.12 enp0s2 Init 2022-01-27 08:00:00 0.300 5.000`
22
23 s := ParseBFDSessions("bfd1", []byte(data))
24
25 assert.Equal(t, 3, len(s), "session count")
26
27 s1 := protocol.BFDSession{
28 ProtocolName: "bfd1",
29 IP: "192.168.64.9",
30 Interface: "enp0s2",
31 Up: true,
32 Since: 3600,
33 SinceEpoch: 1697620076,
34 Interval: 0.1,
35 Timeout: 1,
36 }
37 s2 := protocol.BFDSession{
38 ProtocolName: "bfd1",
39 IP: "192.168.64.10",
40 Interface: "enp0s2",
41 Up: false,
42 Since: 7200,
43 SinceEpoch: 0,
44 Interval: 0.3,
45 Timeout: 0,
46 }
47 s3 := protocol.BFDSession{
48 ProtocolName: "bfd1",
49 IP: "192.168.64.12",
50 Interface: "enp0s2",
51 Up: false,
52 Since: 7200,
53 SinceEpoch: 0,
54 Interval: 0.3,
55 Timeout: 5,
56 }
57 assert.Equal(t, []*protocol.BFDSession{&s1, &s2, &s3}, s, "sessions")
58 }