-
Notifications
You must be signed in to change notification settings - Fork 2
/
metadata_test.go
53 lines (44 loc) · 1.33 KB
/
metadata_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
package suricataparser
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseMetadata(t *testing.T) {
m, err := ParseMetadata("malware_family Crypton, malware_family Nemesis")
require.NoError(t, err)
assert.Len(t, m.Items(), 2)
_, err = ParseMetadata("")
require.Error(t, err)
}
func TestToString(t *testing.T) {
expectedMetadata := "malware_family Crypton, malware_family Nemesis"
m, err := ParseMetadata(expectedMetadata)
require.NoError(t, err)
assert.Equal(t, expectedMetadata, m.String())
}
func TestAddMeta(t *testing.T) {
m, err := ParseMetadata("malware_family Crypton, malware_family Nemesis")
require.NoError(t, err)
m.AddMeta("former_category", "TROJAN")
assert.Len(t, m.items, 3)
}
func TestPopMeta(t *testing.T) {
m, err := ParseMetadata("malware_family Crypton, malware_family Nemesis")
require.NoError(t, err)
// pop key not in meta
m.PopMeta("key")
assert.Len(t, m.items, 2)
// pop key in meta
m.PopMeta("malware_family")
assert.Len(t, m.items, 0)
}
func TestMerge(t *testing.T) {
m1, err := ParseMetadata("malware_family Crypton, malware_family Nemesis")
require.NoError(t, err)
m2, err := ParseMetadata("malware_family Crypton, malware_family Nemesis")
require.NoError(t, err)
assert.Len(t, m1.Items(), 2)
m1.Merge(*m2)
assert.Len(t, m1.Items(), 4)
}