Skip to content

Commit

Permalink
Use mocked time function for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Jan 4, 2021
1 parent e76e9c5 commit 7c3d494
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions operator/builtin/parser/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
)

func TestSyslogParser(t *testing.T) {
now := func() time.Time {
return time.Date(2020, 06, 16, 3, 31, 34, 525, time.UTC)
}

basicConfig := func() *SyslogParserConfig {
cfg := NewSyslogParserConfig("test_operator_id")
cfg.OutputIDs = []string{"fake"}
Expand All @@ -35,7 +39,7 @@ func TestSyslogParser(t *testing.T) {
return cfg
}(),
"<34>Jan 12 06:30:00 1.2.3.4 apache_server: test message",
time.Date(time.Now().Year(), 1, 12, 6, 30, 0, 0, time.UTC),
time.Date(now().Year(), 1, 12, 6, 30, 0, 0, time.UTC),
map[string]interface{}{
"appname": "apache_server",
"facility": 4,
Expand All @@ -54,7 +58,7 @@ func TestSyslogParser(t *testing.T) {
return cfg
}(),
[]byte("<34>Jan 12 06:30:00 1.2.3.4 apache_server: test message"),
time.Date(time.Now().Year(), 1, 12, 6, 30, 0, 0, time.UTC),
time.Date(now().Year(), 1, 12, 6, 30, 0, 0, time.UTC),
map[string]interface{}{
"appname": "apache_server",
"facility": 4,
Expand Down

0 comments on commit 7c3d494

Please sign in to comment.