Fix sloppy test

This commit is contained in:
Olivier Poitrey 2017-06-25 01:12:41 -07:00
parent b42b460ec6
commit 15fc33fe89
1 changed files with 4 additions and 2 deletions

View File

@ -102,6 +102,7 @@ func TestWith(t *testing.T) {
func TestFields(t *testing.T) {
out := &bytes.Buffer{}
log := New(out)
now := time.Now()
log.Log().
Str("foo", "bar").
AnErr("some_err", nil).
@ -121,7 +122,7 @@ func TestFields(t *testing.T) {
Float64("float64", 12).
Dur("dur", 1*time.Second).
Time("time", time.Time{}).
TimeDiff("diff", time.Now(), time.Now().Add(-10*time.Second)).
TimeDiff("diff", now, now.Add(-10*time.Second)).
Msg("")
if got, want := out.String(), `{"foo":"bar","error":"some error","bool":true,"int":1,"int8":2,"int16":3,"int32":4,"int64":5,"uint":6,"uint8":7,"uint16":8,"uint32":9,"uint64":10,"float32":11,"float64":12,"dur":1000,"time":"0001-01-01T00:00:00Z","diff":10000}`+"\n"; got != want {
t.Errorf("invalid log output: got %q, want %q", got, want)
@ -131,6 +132,7 @@ func TestFields(t *testing.T) {
func TestFieldsDisabled(t *testing.T) {
out := &bytes.Buffer{}
log := New(out).Level(InfoLevel)
now := time.Now()
log.Debug().
Str("foo", "bar").
AnErr("some_err", nil).
@ -150,7 +152,7 @@ func TestFieldsDisabled(t *testing.T) {
Float64("float64", 12).
Dur("dur", 1*time.Second).
Time("time", time.Time{}).
TimeDiff("diff", time.Now(), time.Now().Add(-10*time.Second)).
TimeDiff("diff", now, now.Add(-10*time.Second)).
Msg("")
if got, want := out.String(), ""; got != want {
t.Errorf("invalid log output: got %q, want %q", got, want)