testutils

package
v0.55.2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 13 Imported by: 3

Documentation

Overview

Package testutils contains the test utilities and helpers inside the k6 project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterEntries added in v0.45.0

func FilterEntries(logEntries []logrus.Entry, expLevel logrus.Level, expContents string) []logrus.Entry

FilterEntries is a helper function that checks the provided list of log entries for a messages matching the provided level and contents and returns an array with only them.

func LogContains added in v0.38.0

func LogContains(logEntries []logrus.Entry, expLevel logrus.Level, expContents string) bool

LogContains is a helper function that checks the provided list of log entries for a message matching the provided level and contents.

func MakeMemMapFs added in v0.54.0

func MakeMemMapFs(t *testing.T, withFiles map[string][]byte) fsext.Fs

MakeMemMapFs creates a new in-memory filesystem with the given files.

It is particularly useful for testing code that interacts with the filesystem, as it allows to create a filesystem with a known state without having to create temporary directories and files on disk.

The keys of the withFiles map are the paths of the files to create, and the values are the contents of the files. The files are created with 644 mode.

The filesystem is returned as a fsext.Fs.

func NewLogger added in v0.32.0

func NewLogger(t testing.TB) logrus.FieldLogger

NewLogger returns a new logger instance. If the given argument is not nil, the logger will log everything using its t.Logf() method. If its nil, all messages will be discarded.

func NewTestOutput added in v0.27.0

func NewTestOutput(t testing.TB) io.Writer

NewTestOutput returns a simple io.Writer implementation that uses the test's logger as an output.

func Untar added in v0.48.0

func Untar(t *testing.T, fileSystem fsext.Fs, fileName string, destination string) error

Untar a simple test helper that untars a `fileName` file to a `destination` path

Types

type SimpleLogrusHook added in v0.24.0

type SimpleLogrusHook struct {
	HookedLevels []logrus.Level
	// contains filtered or unexported fields
}

SimpleLogrusHook implements the logrus.Hook interface and could be used to check if log messages were outputted

func NewLogHook added in v0.44.0

func NewLogHook(levels ...logrus.Level) *SimpleLogrusHook

NewLogHook creates a new SimpleLogrusHook with the given levels and returns it. If no levels are specified, then logrus.AllLevels will be used.

func NewLoggerWithHook added in v0.44.0

func NewLoggerWithHook(t testing.TB, levels ...logrus.Level) (logrus.FieldLogger, *SimpleLogrusHook)

NewLoggerWithHook calls NewLogger() and attaches a hook with the given levels. If no levels are specified, then logrus.AllLevels will be used and the lowest log level will be Debug.

func (*SimpleLogrusHook) Drain added in v0.24.0

func (smh *SimpleLogrusHook) Drain() []logrus.Entry

Drain returns the currently stored messages and deletes them from the cache

func (*SimpleLogrusHook) Fire added in v0.24.0

func (smh *SimpleLogrusHook) Fire(e *logrus.Entry) error

Fire saves whatever message the logrus library passed in the cache

func (*SimpleLogrusHook) LastEntry added in v0.44.0

func (smh *SimpleLogrusHook) LastEntry() *logrus.Entry

LastEntry returns the last entry that was logged (or nil, if no messages were logged or remain).

func (*SimpleLogrusHook) Levels added in v0.24.0

func (smh *SimpleLogrusHook) Levels() []logrus.Level

Levels just returns whatever was stored in the HookedLevels slice

func (*SimpleLogrusHook) Lines added in v0.43.0

func (smh *SimpleLogrusHook) Lines() []string

Lines returns the logged lines.

func (*SimpleLogrusHook) Reset added in v0.44.0

func (smh *SimpleLogrusHook) Reset()

Reset clears the internal entry buffer.

Directories

Path Synopsis
Package grpcservice contains the implementation of the test GRPC service.
Package grpcservice contains the implementation of the test GRPC service.
Package httpmultibin is intended only for use in tests, do not import in production code!
Package httpmultibin is intended only for use in tests, do not import in production code!
grpc_wrappers_testing
Package grpc_wrappers_testing provides a test service that could be used for the testing gRPC wrappers
Package grpc_wrappers_testing provides a test service that could be used for the testing gRPC wrappers
Package minirunner provides a mock implementation of the lib.Runner We use it in tests
Package minirunner provides a mock implementation of the lib.Runner We use it in tests
Package mockoutput implements a mock output for testing purposes.
Package mockoutput implements a mock output for testing purposes.
Package mockresolver provides a mock implementation of netext.Resolver.
Package mockresolver provides a mock implementation of netext.Resolver.

Jump to

Keyboard shortcuts

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