Skip to content

Commit b814aae

Browse files
committed
add test for null handling
1 parent 962ed21 commit b814aae

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"timestamp":"2017-03-06T06:54:10.839668+0000","flow_id":null,"in_iface":"enp2s0f1","event_type":"fileinfo","vlan":null,"src_ip":null,"src_port":null,"dest_ip":null,"dest_port":null,"http":{"hostname":"api.icndb.com","url":null,"state":"CLOSED","md5":null}}

util/util_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import (
1212
"github.com/DCSO/fever/types"
1313
)
1414

15+
var nullEntry = types.Entry{
16+
Timestamp: "2017-03-06T06:54:10.839668+0000",
17+
EventType: "fileinfo",
18+
JSONLine: `{"timestamp":"2017-03-06T06:54:10.839668+0000","flow_id":null,"in_iface":"enp2s0f1","event_type":"fileinfo","vlan":null,"src_ip":null,"src_port":null,"dest_ip":null,"dest_port":null,"http":{"hostname":"api.icndb.com","url":null,"state":"CLOSED","md5":null}}`,
19+
Iface: "enp2s0f1",
20+
HTTPHost: "api.icndb.com",
21+
}
22+
1523
var entries = []types.Entry{
1624
types.Entry{
1725
SrcIP: "10.0.0.10",
@@ -127,6 +135,31 @@ func TestJSONParseEVEempty(t *testing.T) {
127135
}
128136
}
129137

138+
func TestJSONParseEVEwithnull(t *testing.T) {
139+
f, err := os.Open("testdata/jsonparse_eve_nulls.json")
140+
if err != nil {
141+
t.Fatalf(err.Error())
142+
}
143+
scanner := bufio.NewScanner(f)
144+
i := 0
145+
var entry types.Entry
146+
for scanner.Scan() {
147+
json := scanner.Bytes()
148+
e, err := ParseJSON(json)
149+
if err != nil {
150+
t.Fatalf(err.Error())
151+
}
152+
entry = e
153+
i++
154+
}
155+
if i != 1 {
156+
t.Fatalf("should parse only one entry, got %d", i)
157+
}
158+
if !reflect.DeepEqual(nullEntry, entry) {
159+
t.Fatalf("entry %d parsed from JSON does not match expected value", i)
160+
}
161+
}
162+
130163
func TestGetSensorID(t *testing.T) {
131164
sid, err := GetSensorID()
132165
if err != nil {

0 commit comments

Comments
 (0)