mirror of https://github.com/sirupsen/logrus.git
test the error to ensure there isn't an unexpected error in the test
This commit is contained in:
parent
f9951ccddd
commit
46015a925f
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue