|
@@ -4,34 +4,33 @@ import (
|
|
|
"testing"
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
|
|
|
- "github.com/crowdsecurity/go-cs-lib/ptr"
|
|
|
+ "github.com/crowdsecurity/go-cs-lib/cstest"
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
|
|
)
|
|
|
|
|
|
func TestDateParse(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
- name string
|
|
|
- evt types.Event
|
|
|
- expected_err *error
|
|
|
- expected_strTime *string
|
|
|
+ name string
|
|
|
+ evt types.Event
|
|
|
+ expectedErr string
|
|
|
+ expected string
|
|
|
}{
|
|
|
{
|
|
|
name: "RFC3339",
|
|
|
evt: types.Event{
|
|
|
StrTime: "2019-10-12T07:20:50.52Z",
|
|
|
},
|
|
|
- expected_err: nil,
|
|
|
- expected_strTime: ptr.Of("2019-10-12T07:20:50.52Z"),
|
|
|
+ expected: "2019-10-12T07:20:50.52Z",
|
|
|
},
|
|
|
{
|
|
|
name: "02/Jan/2006:15:04:05 -0700",
|
|
|
evt: types.Event{
|
|
|
StrTime: "02/Jan/2006:15:04:05 -0700",
|
|
|
},
|
|
|
- expected_err: nil,
|
|
|
- expected_strTime: ptr.Of("2006-01-02T15:04:05-07:00"),
|
|
|
+ expected: "2006-01-02T15:04:05-07:00",
|
|
|
},
|
|
|
{
|
|
|
name: "Dec 17 08:17:43",
|
|
@@ -39,8 +38,7 @@ func TestDateParse(t *testing.T) {
|
|
|
StrTime: "2011 X 17 zz 08X17X43 oneone Dec",
|
|
|
StrTimeFormat: "2006 X 2 zz 15X04X05 oneone Jan",
|
|
|
},
|
|
|
- expected_err: nil,
|
|
|
- expected_strTime: ptr.Of("2011-12-17T08:17:43Z"),
|
|
|
+ expected: "2011-12-17T08:17:43Z",
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -51,19 +49,11 @@ func TestDateParse(t *testing.T) {
|
|
|
tt := tt
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
strTime, err := ParseDate(tt.evt.StrTime, &tt.evt, nil, logger)
|
|
|
- if tt.expected_err != nil {
|
|
|
- if err != *tt.expected_err {
|
|
|
- t.Errorf("%s: expected error %v, got %v", tt.name, tt.expected_err, err)
|
|
|
- }
|
|
|
- } else if err != nil {
|
|
|
- t.Errorf("%s: expected no error, got %v", tt.name, err)
|
|
|
- }
|
|
|
- if err != nil {
|
|
|
+ cstest.RequireErrorContains(t, err, tt.expectedErr)
|
|
|
+ if tt.expectedErr != "" {
|
|
|
return
|
|
|
}
|
|
|
- if tt.expected_strTime != nil && strTime["MarshaledTime"] != *tt.expected_strTime {
|
|
|
- t.Errorf("expected strTime %s, got %s", *tt.expected_strTime, strTime["MarshaledTime"])
|
|
|
- }
|
|
|
+ assert.Equal(t, tt.expected, strTime["MarshaledTime"])
|
|
|
})
|
|
|
}
|
|
|
}
|