Skip to content

Add test log recording for assertions based on recorded logs

Compare
Choose a tag to compare
@bt-justtrack bt-justtrack released this 16 May 15:49
· 9 commits to main since this release
v0.18.1
b572d75

What's Changed

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)