MCPcopy
hub / github.com/sirupsen/logrus / TestHookEntryIsPristine

Function TestHookEntryIsPristine

hook_test.go:106–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestHookEntryIsPristine(t *testing.T) {
107 l := New()
108 b := &bytes.Buffer{}
109 l.Formatter = &JSONFormatter{}
110 l.Out = b
111 l.AddHook(&SingleLevelModifyHook{})
112
113 l.Error("error message")
114 data := map[string]string{}
115 err := json.Unmarshal(b.Bytes(), &data)
116 require.NoError(t, err)
117 _, ok := data["wow"]
118 require.False(t, ok)
119 b.Reset()
120
121 l.Info("error message")
122 data = map[string]string{}
123 err = json.Unmarshal(b.Bytes(), &data)
124 require.NoError(t, err)
125 _, ok = data["wow"]
126 require.True(t, ok)
127 b.Reset()
128
129 l.Error("error message")
130 data = map[string]string{}
131 err = json.Unmarshal(b.Bytes(), &data)
132 require.NoError(t, err)
133 _, ok = data["wow"]
134 require.False(t, ok)
135 b.Reset()
136}
137
138type ErrorHook struct {
139 Fired bool

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
AddHookMethod · 0.80
BytesMethod · 0.80
ResetMethod · 0.80
ErrorMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected