1
2
3
4
5
6
7
8
9
10
11
12
13
14 package procfs
15
16 import (
17 "bytes"
18 "reflect"
19 "testing"
20 )
21
22 func TestParseConntrackStat(t *testing.T) {
23 var nfConntrackStat = []byte(`entries searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete search_restart
24 00000021 00000000 00000000 00000000 00000003 0000588a 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
25 00000021 00000000 00000000 00000000 00000002 000056a4 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000002
26 00000021 00000000 00000000 00000000 00000001 000058d4 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001
27 00000021 00000000 00000000 00000000 0000002f 00005688 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000004
28 `)
29 r := bytes.NewReader(nfConntrackStat)
30
31 have, err := parseConntrackStat(r)
32 if err != nil {
33 t.Fatal(err)
34 }
35
36 want := []ConntrackStatEntry{
37 ConntrackStatEntry{
38 Entries: 33,
39 Found: 0,
40 Invalid: 3,
41 Ignore: 22666,
42 Insert: 0,
43 InsertFailed: 0,
44 Drop: 0,
45 EarlyDrop: 0,
46 SearchRestart: 0,
47 },
48 ConntrackStatEntry{
49 Entries: 33,
50 Found: 0,
51 Invalid: 2,
52 Ignore: 22180,
53 Insert: 0,
54 InsertFailed: 0,
55 Drop: 0,
56 EarlyDrop: 0,
57 SearchRestart: 2,
58 },
59 ConntrackStatEntry{
60 Entries: 33,
61 Found: 0,
62 Invalid: 1,
63 Ignore: 22740,
64 Insert: 0,
65 InsertFailed: 0,
66 Drop: 0,
67 EarlyDrop: 0,
68 SearchRestart: 1,
69 },
70 ConntrackStatEntry{
71 Entries: 33,
72 Found: 0,
73 Invalid: 47,
74 Ignore: 22152,
75 Insert: 0,
76 InsertFailed: 0,
77 Drop: 0,
78 EarlyDrop: 0,
79 SearchRestart: 4,
80 },
81 }
82 if !reflect.DeepEqual(want, have) {
83 t.Errorf("want %v, have %v", want, have)
84 }
85 }
86
87 func TestParseOldConntrackStat(t *testing.T) {
88 var nfConntrackStat = []byte(`entries searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error expect_new expect_create expect_delete
89 0000002b 0003159f 02e6786a 00142562 0001bf93 00e1a051 00142537 000b8fe0 000b900b 00000000 00000000 00000000 0001b46a 00000000 00000000 00000000
90 `)
91 r := bytes.NewReader(nfConntrackStat)
92
93 have, err := parseConntrackStat(r)
94 if err != nil {
95 t.Fatal(err)
96 }
97
98 want := []ConntrackStatEntry{
99 ConntrackStatEntry{
100 Entries: 43,
101 Searched: 202143,
102 Found: 48658538,
103 New: 1320290,
104 Invalid: 114579,
105 Ignore: 14786641,
106 Delete: 1320247,
107 DeleteList: 757728,
108 Insert: 757771,
109 InsertFailed: 0,
110 Drop: 0,
111 EarlyDrop: 0,
112 SearchRestart: 0,
113 },
114 }
115 if !reflect.DeepEqual(want, have) {
116 t.Errorf("want %v, have %v", want, have)
117 }
118 }
119
View as plain text