AuditLogContents returns that the audit logs produced by function f.
(t testing.TB, f func(t testing.TB))
| 444 | |
| 445 | // AuditLogContents returns that the audit logs produced by function f. |
| 446 | func AuditLogContents(t testing.TB, f func(t testing.TB)) []byte { |
| 447 | // Temporarily override logger output |
| 448 | b := &bytes.Buffer{} |
| 449 | mw := io.MultiWriter(b, os.Stderr) |
| 450 | auditLogger.Load().logger.SetOutput(mw) |
| 451 | |
| 452 | // Call the given function |
| 453 | f(t) |
| 454 | |
| 455 | FlushLogBuffers() |
| 456 | auditLogger.Load().FlushBufferToLog() |
| 457 | // do not reset output in defer, since we are accessing b.bytes() |
| 458 | auditLogger.Load().logger.SetOutput(os.Stderr) |
| 459 | return b.Bytes() |
| 460 | } |