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

Function TestHijackLogrus_Error

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

Source from the content-addressed store, hash-verified

72}
73
74func 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
102func rcvCtx[T any](ctx context.Context, t *testing.T, ch <-chan T) (v T) {
103 t.Helper()

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