MCPcopy
hub / github.com/uber-go/zap / TestCheckedEntryWrite

Function TestCheckedEntryWrite

zapcore/entry_test.go:106–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestCheckedEntryWrite(t *testing.T) {
107 t.Run("nil is safe", func(t *testing.T) {
108 var ce *CheckedEntry
109 assert.NotPanics(t, func() { ce.Write() }, "Unexpected panic writing nil CheckedEntry.")
110 })
111
112 t.Run("WriteThenPanic", func(t *testing.T) {
113 var ce *CheckedEntry
114 ce = ce.After(Entry{}, WriteThenPanic)
115 assert.Panics(t, func() { ce.Write() }, "Expected to panic when WriteThenPanic is set.")
116 })
117
118 t.Run("WriteThenGoexit", func(t *testing.T) {
119 var ce *CheckedEntry
120 ce = ce.After(Entry{}, WriteThenGoexit)
121 assertGoexit(t, func() { ce.Write() })
122 })
123
124 t.Run("WriteThenFatal", func(t *testing.T) {
125 var ce *CheckedEntry
126 ce = ce.After(Entry{}, WriteThenFatal)
127 stub := exit.WithStub(func() {
128 ce.Write()
129 })
130 assert.True(t, stub.Exited, "Expected to exit when WriteThenFatal is set.")
131 assert.Equal(t, 1, stub.Code, "Expected to exit when WriteThenFatal is set.")
132 })
133
134 t.Run("After", func(t *testing.T) {
135 var ce *CheckedEntry
136 hook := &customHook{}
137 ce = ce.After(Entry{}, hook)
138 ce.Write()
139 assert.True(t, hook.called, "Expected to call custom action after Write.")
140 })
141}
142
143type customHook struct {
144 called bool

Callers

nothing calls this directly

Calls 4

WriteMethod · 0.95
AfterMethod · 0.95
WithStubFunction · 0.92
assertGoexitFunction · 0.85

Tested by

no test coverage detected