test the error to ensure there isn't an unexpected error in the test

This commit is contained in:
Edward Muller 2019-10-13 17:45:01 -07:00
parent f9951ccddd
commit 46015a925f
No known key found for this signature in database
GPG Key ID: FC5833DB021899A5
3 changed files with 14 additions and 5 deletions

View File

@ -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, "second hook") }})
h.Add(&HookCallFunc{F: func() { checkers = append(checkers, "third 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) require.Equal(t, []string{"first hook", "second hook", "third hook"}, checkers)
} }

View File

@ -21,7 +21,9 @@ func TestFieldValueError(t *testing.T) {
l.WithField("func", func() {}).Info("test") l.WithField("func", func() {}).Info("test")
fmt.Println(buf.String()) fmt.Println(buf.String())
var data map[string]interface{} 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] _, ok := data[FieldKeyLogrusError]
require.True(t, ok) require.True(t, ok)
} }
@ -37,7 +39,9 @@ func TestNoFieldValueError(t *testing.T) {
l.WithField("str", "str").Info("test") l.WithField("str", "str").Info("test")
fmt.Println(buf.String()) fmt.Println(buf.String())
var data map[string]interface{} 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] _, ok := data[FieldKeyLogrusError]
require.False(t, ok) require.False(t, ok)
} }

View File

@ -656,11 +656,14 @@ func TestEntryWriter(t *testing.T) {
log := New() log := New()
log.Out = cw log.Out = cw
log.Formatter = new(JSONFormatter) 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 bs := <-cw
var fields Fields var fields Fields
err := json.Unmarshal(bs, &fields) err = json.Unmarshal(bs, &fields)
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, fields["foo"], "bar") assert.Equal(t, fields["foo"], "bar")
assert.Equal(t, fields["level"], "warning") assert.Equal(t, fields["level"], "warning")