Documentation ¶
Overview ¶
The testlogrus package exposes two functions to use during testing.
When calling `Logs` function, the logs are reset, as such if multiple verification are to be done, you should first affect `Logs` result to a variable.
func TestSome(t *testing.T) { t.Run("error_test", func(t *testing.T) { // Arrange // mandatory call to setup logrus logging hook // logging hook is set to nil at the end of t.Run testlogrus.CatchLogs(t) // Act // call some functions that log with logrus // Assert logs := testlogrus.Logs() // assert some things around function expected logs }) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoHook = errors.New("testlogrus hook wasn't initialized with CatchLogs")
ErrNoHook is the panic error in case Logs is called without a previous call to CatchLogs.
Functions ¶
func CatchLogs ¶
CatchLogs creates a hook over logrus logs. Easy to use with Logs function to catch written logs in tests.
Useful to confirm logging behavior over application.
Note that at the end of t.Run a cleanup is called to reset the hook. As such CatchLogs must either be called at the beginning of every t.Run needing a log verification or at the beginning of every test function (TestXXX) needing logs verification.
Types ¶
This section is empty.