testkit

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package testkit provides lightweight test helpers for chassis-go services. It has zero dependencies on other chassis packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the OS for an available TCP port by listening on :0, then closes the listener and returns the assigned port. This is useful for parallel tests that each need their own listener.

func NewLogger

func NewLogger(t testing.TB) *slog.Logger

NewLogger returns a *slog.Logger that writes JSON output to t.Log so that log lines appear alongside test output and are suppressed on success unless -v is passed. The level is set to Debug so every message is captured.

func SetEnv

func SetEnv(t testing.TB, envs map[string]string)

SetEnv sets the supplied environment variables and registers a t.Cleanup to unset them after the test. This is the building block for test config — pair it with config.MustLoad[T]() in your test to load typed configuration.

Example:

testkit.SetEnv(t, map[string]string{"PORT": "8080"})
cfg := config.MustLoad[AppConfig]()

Types

This section is empty.

Jump to

Keyboard shortcuts

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