(t *testing.T)
| 72 | } |
| 73 | |
| 74 | func TestHijackLogrus_Error(t *testing.T) { |
| 75 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 76 | t.Cleanup(cancel) |
| 77 | messages := make(chan *logrus.Entry) |
| 78 | |
| 79 | logf := func(entry *logrus.Entry) { |
| 80 | t.Logf("got msg level: %s msg: %q", entry.Level, entry.Message) |
| 81 | messages <- entry |
| 82 | } |
| 83 | |
| 84 | log.HijackLogrus(log.LevelError, logf) |
| 85 | |
| 86 | done := make(chan struct{}) |
| 87 | go func() { |
| 88 | defer close(done) |
| 89 | // The following should be filtered out. |
| 90 | logrus.Trace("Tracing!") |
| 91 | logrus.Debug("Debugging!") |
| 92 | logrus.Info("Testing!") |
| 93 | logrus.Warn("Warning!") |
| 94 | // We should receive the below. |
| 95 | logrus.Error("Error!") |
| 96 | }() |
| 97 | |
| 98 | require.Equal(t, "Error!", rcvCtx(ctx, t, messages).Message) |
| 99 | <-done |
| 100 | } |
| 101 | |
| 102 | func rcvCtx[T any](ctx context.Context, t *testing.T, ch <-chan T) (v T) { |
| 103 | t.Helper() |
nothing calls this directly
no test coverage detected