testlogrus

package
v2.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

The testlogrus packages 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
		testlogrus.CatchLogs()

		// 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

View Source
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

func CatchLogs()

CatchLogs creates a hook over logrus logs. Easy to use with Logs function to then catch written logs in tests.

Useful to confirm logging behavior over application.

func Logs

func Logs() string

Logs resets the logrus test logs hooks and returns all catched logs from when CatchLogs was executed.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL