forked from mirror/logrus
Merge pull request #796 from sirupsen/fix/entry_empty_fields
Ensure a new entry data fields are empty
This commit is contained in:
commit
d329d24db4
43
hook_test.go
43
hook_test.go
|
@ -1,10 +1,13 @@
|
|||
package logrus
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type TestHook struct {
|
||||
|
@ -85,6 +88,46 @@ func TestCanFireMultipleHooks(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
type SingleLevelModifyHook struct {
|
||||
ModifyHook
|
||||
}
|
||||
|
||||
func (h *SingleLevelModifyHook) Levels() []Level {
|
||||
return []Level{InfoLevel}
|
||||
}
|
||||
|
||||
func TestHookEntryIsPristine(t *testing.T) {
|
||||
l := New()
|
||||
b := &bytes.Buffer{}
|
||||
l.Formatter = &JSONFormatter{}
|
||||
l.Out = b
|
||||
l.AddHook(&SingleLevelModifyHook{})
|
||||
|
||||
l.Error("error message")
|
||||
data := map[string]string{}
|
||||
err := json.Unmarshal(b.Bytes(), &data)
|
||||
require.NoError(t, err)
|
||||
_, ok := data["wow"]
|
||||
require.False(t, ok)
|
||||
b.Reset()
|
||||
|
||||
l.Info("error message")
|
||||
data = map[string]string{}
|
||||
err = json.Unmarshal(b.Bytes(), &data)
|
||||
require.NoError(t, err)
|
||||
_, ok = data["wow"]
|
||||
require.True(t, ok)
|
||||
b.Reset()
|
||||
|
||||
l.Error("error message")
|
||||
data = map[string]string{}
|
||||
err = json.Unmarshal(b.Bytes(), &data)
|
||||
require.NoError(t, err)
|
||||
_, ok = data["wow"]
|
||||
require.False(t, ok)
|
||||
b.Reset()
|
||||
}
|
||||
|
||||
type ErrorHook struct {
|
||||
Fired bool
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue