Skip to content

Commit

Permalink
test the error to ensure there isn't an unexpected error in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Muller committed Oct 14, 2019
1 parent 213f203 commit ad7a716
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ func TestHookFireOrder(t *testing.T) {
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "second hook") }})
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "third hook") }})

h.Fire(InfoLevel, &Entry{})
if err := h.Fire(InfoLevel, &Entry{}); err != nil {
t.Error("unexpected error:", err)
}
require.Equal(t, []string{"first hook", "second hook", "third hook"}, checkers)
}
8 changes: 6 additions & 2 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func TestFieldValueError(t *testing.T) {
l.WithField("func", func() {}).Info("test")
fmt.Println(buf.String())
var data map[string]interface{}
json.Unmarshal(buf.Bytes(), &data)
if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
t.Error("unexpected error", err)
}
_, ok := data[FieldKeyLogrusError]
require.True(t, ok)
}
Expand All @@ -37,7 +39,9 @@ func TestNoFieldValueError(t *testing.T) {
l.WithField("str", "str").Info("test")
fmt.Println(buf.String())
var data map[string]interface{}
json.Unmarshal(buf.Bytes(), &data)
if err := json.Unmarshal(buf.Bytes(), &data); err != nil {
t.Error("unexpected error", err)
}
_, ok := data[FieldKeyLogrusError]
require.False(t, ok)
}
Expand Down
7 changes: 5 additions & 2 deletions logrus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,14 @@ func TestEntryWriter(t *testing.T) {
log := New()
log.Out = cw
log.Formatter = new(JSONFormatter)
log.WithField("foo", "bar").WriterLevel(WarnLevel).Write([]byte("hello\n"))
_, err := log.WithField("foo", "bar").WriterLevel(WarnLevel).Write([]byte("hello\n"))
if err != nil {
t.Error("unexecpted error", err)
}

bs := <-cw
var fields Fields
err := json.Unmarshal(bs, &fields)
err = json.Unmarshal(bs, &fields)
assert.Nil(t, err)
assert.Equal(t, fields["foo"], "bar")
assert.Equal(t, fields["level"], "warning")
Expand Down

0 comments on commit ad7a716

Please sign in to comment.