-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from satta/time-marshaling
ensure proper time marshaling
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package types | ||
|
||
// DCSO FEVER | ||
// Copyright (c) 2019, DCSO GmbH | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func TestEVERoundtripTimestamp(t *testing.T) { | ||
timeCmp, _ := time.Parse(time.RFC3339, "2019-08-06 13:30:01.690233 +0200 CEST") | ||
ee := EveEvent{ | ||
Timestamp: &suriTime{ | ||
Time: timeCmp, | ||
}, | ||
EventType: "http", | ||
SrcIP: "1.2.3.4", | ||
SrcPort: 2222, | ||
DestIP: "3.4.5.6", | ||
DestPort: 80, | ||
Proto: "tcp", | ||
HTTP: &HTTPEvent{ | ||
Hostname: "test", | ||
URL: "/", | ||
}, | ||
} | ||
|
||
out, err := json.Marshal(ee) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
var inEVE EveEvent | ||
err = json.Unmarshal(out, &inEVE) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if !inEVE.Timestamp.Time.Equal(ee.Timestamp.Time) { | ||
t.Fatalf("timestamp round-trip failed: %v <-> %v", inEVE.Timestamp, ee.Timestamp) | ||
} else { | ||
log.Info("timestamps ok") | ||
} | ||
} |