From 46015a925f6ddae74035f54adad8d9042f747276 Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Sun, 13 Oct 2019 17:45:01 -0700 Subject: [PATCH] test the error to ensure there isn't an unexpected error in the test --- hook_test.go | 4 +++- logger_test.go | 8 ++++++-- logrus_test.go | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hook_test.go b/hook_test.go index 28f193d..b5cf077 100644 --- a/hook_test.go +++ b/hook_test.go @@ -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) } diff --git a/logger_test.go b/logger_test.go index 50433e6..f12a04e 100644 --- a/logger_test.go +++ b/logger_test.go @@ -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) } diff --git a/logrus_test.go b/logrus_test.go index 51f09a2..9c3c920 100644 --- a/logrus_test.go +++ b/logrus_test.go @@ -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")