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

Function TestHijackLogrus_Debug

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

Source from the content-addressed store, hash-verified

41}
42
43func TestHijackLogrus_Debug(t *testing.T) {
44 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
45 t.Cleanup(cancel)
46 messages := make(chan *logrus.Entry)
47
48 logf := func(entry *logrus.Entry) {
49 t.Logf("got msg level: %s msg: %q", entry.Level, entry.Message)
50 messages <- entry
51 }
52
53 log.HijackLogrus(log.LevelDebug, logf)
54
55 done := make(chan struct{})
56 go func() {
57 defer close(done)
58 // The following should be filtered out.
59 logrus.Trace("Tracing!")
60 // We should receive the below.
61 logrus.Debug("Debugging!")
62 logrus.Info("Testing!")
63 logrus.Warn("Warning!")
64 logrus.Error("Error!")
65 }()
66
67 require.Equal(t, "Debugging!", rcvCtx(ctx, t, messages).Message)
68 require.Equal(t, "Testing!", rcvCtx(ctx, t, messages).Message)
69 require.Equal(t, "Warning!", rcvCtx(ctx, t, messages).Message)
70 require.Equal(t, "Error!", rcvCtx(ctx, t, messages).Message)
71 <-done
72}
73
74func TestHijackLogrus_Error(t *testing.T) {
75 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