-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow passing current time source.
- Loading branch information
Showing
3 changed files
with
35 additions
and
2 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
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,20 @@ | ||
package zap | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zaptest/observer" | ||
) | ||
|
||
func TestWithTimeSource(t *testing.T) { | ||
date := time.Date(2077, 1, 23, 10, 15, 13, 441, time.UTC) | ||
now := func() time.Time { return date } | ||
withLogger(t, DebugLevel, []Option{WithTimeSource(now)}, func(log *Logger, logs *observer.ObservedLogs) { | ||
log.Info("") | ||
require.Equal(t, 1, logs.Len(), "Expected only one log entry to be written.") | ||
assert.Equal(t, date, logs.All()[0].Entry.Time, "Unexpected entry time.") | ||
}) | ||
} |