-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathstats_test.go
122 lines (107 loc) · 2.35 KB
/
stats_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package conntrack
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/ti-mo/netfilter"
)
func TestStatsUnmarshal(t *testing.T) {
nfa := []netfilter.Attribute{
{
Type: uint16(ctaStatsFound),
Data: []byte{0x01, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsInvalid),
Data: []byte{0x02, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsIgnore),
Data: []byte{0x03, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsInsert),
Data: []byte{0x04, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsInsertFailed),
Data: []byte{0x05, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsDrop),
Data: []byte{0x06, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsEarlyDrop),
Data: []byte{0x07, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsError),
Data: []byte{0x08, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsSearchRestart),
Data: []byte{0x09, 0xab, 0xcd, 0xef},
},
{Type: uint16(ctaStatsSearched)},
{Type: uint16(ctaStatsNew)},
{Type: uint16(ctaStatsDelete)},
{Type: uint16(ctaStatsDeleteList)},
}
want := Stats{
Found: 0x01abcdef,
Invalid: 0x02abcdef,
Ignore: 0x03abcdef,
Insert: 0x04abcdef,
InsertFailed: 0x05abcdef,
Drop: 0x06abcdef,
EarlyDrop: 0x07abcdef,
Error: 0x08abcdef,
SearchRestart: 0x09abcdef,
}
var s Stats
s.unmarshal(nfa)
assert.Equal(t, want, s, "unexpected unmarshal")
}
func TestStatsExpectUnmarshal(t *testing.T) {
nfa := []netfilter.Attribute{
{
Type: uint16(ctaStatsExpNew),
Data: []byte{0x01, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsExpCreate),
Data: []byte{0x02, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsExpDelete),
Data: []byte{0x03, 0xab, 0xcd, 0xef},
},
}
want := StatsExpect{
New: 0x01abcdef,
Create: 0x02abcdef,
Delete: 0x03abcdef,
}
var se StatsExpect
se.unmarshal(nfa)
assert.Equal(t, want, se, "unexpected unmarshal")
}
func TestStatsGlobalUnmarshal(t *testing.T) {
nfa := []netfilter.Attribute{
{
Type: uint16(ctaStatsGlobalEntries),
Data: []byte{0x01, 0xab, 0xcd, 0xef},
},
{
Type: uint16(ctaStatsGlobalMaxEntries),
Data: []byte{0x02, 0xab, 0xcd, 0xef},
},
}
want := StatsGlobal{
Entries: 0x01abcdef,
MaxEntries: 0x02abcdef,
}
var sg StatsGlobal
sg.unmarshal(nfa)
assert.Equal(t, want, sg, "unexpected unmarshal")
}