testlog

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Substrings

func Substrings(t *testing.T) (h slog.Handler, want func(string))

Substrings returns a slog.Handler and a "want" function.

When a logging call is made using the handler, log lines are written to a buffer. Calling "want" tests whether the buffer contains the given string. If it does not, t.Errorf is called. Calling want clears the buffer.

The handler encodes to JSON, and adds source/line information.

Types

type TB

type TB struct {
	// turns time on / off in logs
	Time bool

	// adjust depth
	Depth int

	// embed testing.TB, get a lot of free methods...
	testing.TB
	// contains filtered or unexported fields
}

type TB embeds testing.TB, and has the following utility:

  • TB overrides some testing.TB methods, and embeds others - it satisifes the testing.TB interface
  • TB also satisfies the slog.Handler interface
  • TB provides a method Want, for substring matching of logged output
  • TB provides a method WantBuffer, for string matching of logged output

func UsingTB

func UsingTB(ttb testing.TB) *TB

func (*TB) Clear

func (tb *TB) Clear()

func (*TB) Enabled

func (tb *TB) Enabled(level slog.Level) bool

func (*TB) Error

func (tb *TB) Error(args ...any)

func (*TB) Errorf

func (tb *TB) Errorf(format string, args ...any)

func (*TB) Fatal

func (tb *TB) Fatal(args ...any)

func (*TB) Fatalf

func (tb *TB) Fatalf(format string, args ...any)

func (*TB) Handle

func (tb *TB) Handle(r slog.Record) error

func (*TB) Log

func (tb *TB) Log(args ...any)

func (*TB) Logf

func (tb *TB) Logf(format string, args ...any)

func (*TB) Setenv

func (tb *TB) Setenv(key, value string)

func (*TB) Skip

func (tb *TB) Skip(args ...any)

func (*TB) Skipf

func (tb *TB) Skipf(format string, args ...any)

func (*TB) Want

func (tb *TB) Want(want string) (found bool)

func (*TB) WantBuffer

func (tb *TB) WantBuffer(want string) (found bool)

func (*TB) WithAttrs

func (tb *TB) WithAttrs(as []slog.Attr) slog.Handler

func (*TB) WithGroup

func (tb *TB) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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