MCPcopy Create free account
hub / github.com/coder/envbuilder / TestHijackLogrus_Info

Function TestHijackLogrus_Info

log/logrus_test.go:13–41  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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
43func TestHijackLogrus_Debug(t *testing.T) {
44 ctx, cancel := context.WithTimeout(context.Background(), time.Second)

Callers

nothing calls this directly

Calls 4

HijackLogrusFunction · 0.92
rcvCtxFunction · 0.85
InfoMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected