xt

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const EnvNoColors = "XT_NO_COLORS"

Variables

View Source
var TestHelper = (*testing.T).Helper

Functions

func Assert

func Assert(t *testing.T, condition bool, messages ...string)

Assert checks if condition is true. When not, messages are displayed. This is equivalent as Eq(t, true, condition, messages...).

func Eq

func Eq(t *testing.T, want, have any, messages ...string)

Eq checks if the `want` value is equal to the `have` value during testing. If not equal, it triggers a test failure with optional custom `messages`.

This function uses reflection for comparison and handles nil values.

func ErrorIs added in v1.11.0

func ErrorIs(t *testing.T, want, have error, messages ...string)

ErrorIs checks whether the provided errors are the same when not wrapping or whether the have-error is wrapped in the have-error.

func KO

func KO(t *testing.T, err error, messages ...string)

KO checks whether err is not nil.

Reverse of OK, and also, well, you know 💥🥊.

This could be replaced with using Eq, but since checking the error in Go is done lots, it is nicer to read in tests.

func MatchString

func MatchString(t *testing.T, pattern, s string, messages ...string)

MatchString tests whether the string s matches the regular expression pattern.

func OK

func OK(t *testing.T, err error, messages ...string)

OK checks whether err is nil. This could be replaced with using Eq, but since checking the error in Go is done lots, it is nicer to read in tests.

func Panics

func Panics(t *testing.T, f func())

Panics checks if function f panics.

func PanicsEq

func PanicsEq(t *testing.T, exp string, f func())

PanicsEq checks if function f panics and whether the panic message is equal to exp.

Types

type LogAgg added in v1.5.0

type LogAgg struct {
	// contains filtered or unexported fields
}

LogAgg is a very basic log aggregation writer which can be used to find entries. This is really just useful for tests and also not really specific to logging.

func NewLogAgg added in v1.5.0

func NewLogAgg() *LogAgg

func (*LogAgg) Entries added in v1.5.1

func (l *LogAgg) Entries() []string

Entries returns copy of all entries.

func (*LogAgg) Find added in v1.5.0

func (l *LogAgg) Find(t *testing.T, pattern string) string

Find searches for an entry which matches pattern.

func (*LogAgg) FindJSON added in v1.5.0

func (l *LogAgg) FindJSON(t *testing.T, pattern string) map[string]any

FindJSON searches for an entry which matches pattern and returns the decoded JSON line as map[string]any.

func (*LogAgg) Reset added in v1.5.0

func (l *LogAgg) Reset()

Reset clears all entries.

func (*LogAgg) Write added in v1.5.0

func (l *LogAgg) Write(entry []byte) (n int, err error)

Write stores entry.

Jump to

Keyboard shortcuts

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