captureOutput replaces the logger output with a buffer, runs fn, and returns the output. It restores the original output and level after the test.
(t *testing.T, fn func())
| 19 | // captureOutput replaces the logger output with a buffer, runs fn, and returns the output. |
| 20 | // It restores the original output and level after the test. |
| 21 | func captureOutput(t *testing.T, fn func()) string { |
| 22 | t.Helper() |
| 23 | origOut := logger.Out |
| 24 | origLevel := logger.Level |
| 25 | var buf bytes.Buffer |
| 26 | logger.SetOutput(&buf) |
| 27 | logger.SetLevel(logrus.DebugLevel) |
| 28 | defer func() { |
| 29 | logger.SetOutput(origOut) |
| 30 | logger.SetLevel(origLevel) |
| 31 | }() |
| 32 | fn() |
| 33 | return buf.String() |
| 34 | } |
| 35 | |
| 36 | func TestLoggerInitialized(t *testing.T) { |
| 37 | assert.NotNil(t, logger, "Logger should be initialized by init()") |
no test coverage detected