Documentation
¶
Overview ¶
Package testutils provides testing utilities to aid error handling in tests.
This package contains generic file-related test utilities, testing helpers shared across packages, and various utilities for error handling and test setup/teardown.
Index ¶
- Variables
- func AssertErrContains(t *testing.T, got error, contains string, ctx string)
- func AssertErrWrappedContains(t *testing.T, got error, want error, contains string, ctx string)
- func AssertFileEquals(t *testing.T, dir, path, expected string)
- func AssertStringContains(t *testing.T, haystack string, subs ...string)
- func AssertStringContainsOneOf(t *testing.T, haystack string, options ...string)
- func MustMarshal[T any](t *testing.T, m marshaller.Marshaller[T], v T) string
- func MustUnmarshal[T any](t *testing.T, m marshaller.Marshaller[T], data []byte, out *T)
- func MustUnmarshalString[T any](t *testing.T, m marshaller.Marshaller[T], data string, out *T)
- func RunNameCases(t *testing.T, cases []NameCase, run func(t *testing.T, c NameCase))
- func RunTestMainWithSnapshotCleanup(m *testing.M)
- func SetupExistingFile(t *testing.T, filename string) (string, string, string)
- type NameCase
Constants ¶
This section is empty.
Variables ¶
var ErrTestConfigLoadError = errors.New("test config load error")
ErrTestConfigLoadError is a static test error to comply with err113 and allow reuse across packages.
Functions ¶
func AssertErrContains ¶
AssertErrContains asserts that an error is non-nil and its message contains the provided substring.
func AssertErrWrappedContains ¶
AssertErrWrappedContains verifies that an error exists, wraps a target error, and optionally contains a given substring in its message. "ctx" describes the calling context.
func AssertFileEquals ¶
AssertFileEquals compares the file content with the expected string.
func AssertStringContains ¶
AssertStringContains asserts that the haystack contains all provided substrings.
func AssertStringContainsOneOf ¶
AssertStringContainsOneOf asserts that the haystack contains at least one of the provided options.
func MustMarshal ¶
func MustMarshal[T any](t *testing.T, m marshaller.Marshaller[T], v T) string
MustMarshal marshals a value or fails the test.
func MustUnmarshal ¶
func MustUnmarshal[T any](t *testing.T, m marshaller.Marshaller[T], data []byte, out *T)
MustUnmarshal unmarshals bytes into a value or fails the test.
func MustUnmarshalString ¶
func MustUnmarshalString[T any](t *testing.T, m marshaller.Marshaller[T], data string, out *T)
MustUnmarshalString unmarshals a string into a value or fails the test.
func RunNameCases ¶
RunNameCases runs the provided function for each NameCase with parallel subtests.
func RunTestMainWithSnapshotCleanup ¶
RunTestMainWithSnapshotCleanup runs the standard TestMain pattern with snapshot cleanup. Shared across packages that only need snapshot cleanup (non command-specific logic).
Types ¶
type NameCase ¶
NameCase represents a common test case shape for commands that accept an optional name and default to a configured name when empty.
func DefaultNameCases ¶
DefaultNameCases returns the standard two cases used throughout the repo: 1) explicit name; 2) empty name falls back to default/cfg name.