AssertLogContains asserts that the logs produced by function f contain string s.
(t *testing.T, s string, f func())
| 412 | |
| 413 | // AssertLogContains asserts that the logs produced by function f contain string s. |
| 414 | func AssertLogContains(t *testing.T, s string, f func()) { |
| 415 | // Temporarily override logger output |
| 416 | b := &bytes.Buffer{} |
| 417 | mw := io.MultiWriter(b, os.Stderr) |
| 418 | consoleLogger.Load().logger.SetOutput(mw) |
| 419 | // Call the given function |
| 420 | f() |
| 421 | |
| 422 | FlushLogBuffers() |
| 423 | consoleLogger.Load().FlushBufferToLog() |
| 424 | // do not reset output in defer, since we are accessing b.String() after |
| 425 | consoleLogger.Load().logger.SetOutput(os.Stderr) |
| 426 | assert.Contains(t, b.String(), s) |
| 427 | } |
| 428 | |
| 429 | // AssertLogNotContains asserts that the logs produced by function f do not contain string s. |
| 430 | func AssertLogNotContains(t *testing.T, s string, f func()) { |