|
@@ -9,6 +9,88 @@ import (
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
)
|
|
|
|
|
|
+func TestSetParsed(t *testing.T) {
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ evt *Event
|
|
|
+ key string
|
|
|
+ value string
|
|
|
+ expected bool
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "SetParsed: Valid",
|
|
|
+ evt: &Event{},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "SetParsed: Existing map",
|
|
|
+ evt: &Event{Parsed: map[string]string{}},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "SetParsed: Existing map+key",
|
|
|
+ evt: &Event{Parsed: map[string]string{"test": "foobar"}},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, tt := range tests {
|
|
|
+ tt := tt
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ tt.evt.SetMeta(tt.key, tt.value)
|
|
|
+ assert.Equal(t, tt.value, tt.evt.Parsed[tt.key])
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func TestSetMeta(t *testing.T) {
|
|
|
+ tests := []struct {
|
|
|
+ name string
|
|
|
+ evt *Event
|
|
|
+ key string
|
|
|
+ value string
|
|
|
+ expected bool
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "SetMeta: Valid",
|
|
|
+ evt: &Event{},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "SetMeta: Existing map",
|
|
|
+ evt: &Event{Meta: map[string]string{}},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "SetMeta: Existing map+key",
|
|
|
+ evt: &Event{Meta: map[string]string{"test": "foobar"}},
|
|
|
+ key: "test",
|
|
|
+ value: "test",
|
|
|
+ expected: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, tt := range tests {
|
|
|
+ tt := tt
|
|
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
|
+ tt.evt.SetMeta(tt.key, tt.value)
|
|
|
+ assert.Equal(t, tt.value, tt.evt.GetMeta(tt.key))
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func TestParseIPSources(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
name string
|