(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func 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 | |
| 143 | type customHook struct { |
| 144 | called bool |
nothing calls this directly
no test coverage detected