Add test log recording for assertions based on recorded logs
What's Changed
- appctx: Add documentation by @bt-justtrack in #1101
- suite, env: Implement optional recording of emitted logs for use in test assertions by @bt-justtrack in #1103
The main change is the ability of test/suite.Suite to now accept an option suite.WithLogRecording()
which causes the environment
of the test to collect all log statements issued on its logger.
The test can then get these and make assertions based on them:
logs := s.Env().Logs().Filter(func(lr env.LogRecord) bool {
return strings.Contains(lr.FormattedMsg, "foobar")
})
s.Len(logs, 1)