(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestHijackLogrus_Info(t *testing.T) { |
| 14 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 15 | t.Cleanup(cancel) |
| 16 | messages := make(chan *logrus.Entry) |
| 17 | |
| 18 | logf := func(entry *logrus.Entry) { |
| 19 | t.Logf("got msg level: %s msg: %q", entry.Level, entry.Message) |
| 20 | messages <- entry |
| 21 | } |
| 22 | |
| 23 | log.HijackLogrus(log.LevelInfo, logf) |
| 24 | |
| 25 | done := make(chan struct{}) |
| 26 | go func() { |
| 27 | defer close(done) |
| 28 | // The following should be filtered out. |
| 29 | logrus.Trace("Tracing!") |
| 30 | logrus.Debug("Debugging!") |
| 31 | // We should receive the below. |
| 32 | logrus.Info("Testing!") |
| 33 | logrus.Warn("Warning!") |
| 34 | logrus.Error("Error!") |
| 35 | }() |
| 36 | |
| 37 | require.Equal(t, "Testing!", rcvCtx(ctx, t, messages).Message) |
| 38 | require.Equal(t, "Warning!", rcvCtx(ctx, t, messages).Message) |
| 39 | require.Equal(t, "Error!", rcvCtx(ctx, t, messages).Message) |
| 40 | <-done |
| 41 | } |
| 42 | |
| 43 | func TestHijackLogrus_Debug(t *testing.T) { |
| 44 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
nothing calls this directly
no test coverage detected