The sink is called once per Record while enabled, in order, with the fully-constructed Event.
(t *testing.T)
| 144 | // The sink is called once per Record while enabled, in order, with the |
| 145 | // fully-constructed Event. |
| 146 | func TestSinkReceivesEventsInOrder(t *testing.T) { |
| 147 | debug.SetEnabled(true) |
| 148 | t.Cleanup(func() { |
| 149 | debug.SetEnabled(false) |
| 150 | debug.SetSink(nil) |
| 151 | }) |
| 152 | debug.Clear() |
| 153 | |
| 154 | var got []debug.Event |
| 155 | debug.SetSink(func(e debug.Event) { got = append(got, e) }) |
| 156 | |
| 157 | debug.Record("a", debug.LevelInfo, "first") |
| 158 | debug.Record("b", debug.LevelWarn, "second") |
| 159 | |
| 160 | if len(got) != 2 { |
| 161 | t.Fatalf("sink got %d events, want 2", len(got)) |
| 162 | } |
| 163 | if got[0].Message != "first" || got[1].Message != "second" { |
| 164 | t.Errorf("sink events out of order: %+v", got) |
| 165 | } |
| 166 | if got[0].Source != "a" || got[1].Source != "b" { |
| 167 | t.Errorf("sink dropped Source field: %+v", got) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | // Latest walks back from the newest event to find one with a non-empty |
| 172 | // payload, skipping payload-less events along the way. |
nothing calls this directly
no test coverage detected