testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides lightweight helpers for writing tests in agentwatch. It is internal — do not promote to a public package without a concrete consumer need.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardLogger

func DiscardLogger() *slog.Logger

DiscardLogger returns an *slog.Logger that silently discards all output. Use it when a logger is required but log output is irrelevant to the test.

func LoadFixture

func LoadFixture(t testing.TB, name string) []byte

LoadFixture reads testdata/<name> relative to the calling test's working directory (the package directory). The test fails if the file cannot be read.

func NewLogger

func NewLogger(t testing.TB) (*slog.Logger, *bytes.Buffer)

NewLogger returns an *slog.Logger and a *bytes.Buffer that captures its output at Debug level and above. Use buf.String() in assertions to verify that specific messages were logged.

func RequireEqual

func RequireEqual[T comparable](t testing.TB, want, got T)

RequireEqual fails t immediately if want != got.

func RequireNoError

func RequireNoError(t testing.TB, err error)

RequireNoError fails t immediately if err is non-nil.

func TempDir

func TempDir(t testing.TB) string

TempDir returns a temporary directory that is automatically removed when t ends. It is a thin wrapper around t.TempDir.

func WriteFixture

func WriteFixture(t testing.TB, dir, name string, data []byte) string

WriteFixture writes data to filepath.Join(dir, name) with permissions 0600 and returns the full path. The test fails if the write fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

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