MCPcopy Create free account
hub / github.com/Driver-C/tryssh / captureOutput

Function captureOutput

pkg/utils/logger_test.go:21–34  ·  view source on GitHub ↗

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())

Source from the content-addressed store, hash-verified

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.
21func 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
36func TestLoggerInitialized(t *testing.T) {
37 assert.NotNil(t, logger, "Logger should be initialized by init()")

Callers 12

TestInfoFunction · 0.70
TestInfofFunction · 0.70
TestInfolnFunction · 0.70
TestWarnFunction · 0.70
TestWarnfFunction · 0.70
TestWarnlnFunction · 0.70
TestErrorFunction · 0.70
TestErrorfFunction · 0.70
TestErrorlnFunction · 0.70
TestFatalFunction · 0.70
TestFatalfFunction · 0.70
TestFatallnFunction · 0.70

Calls 1

StringMethod · 0.80

Tested by

no test coverage detected