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 ¶
- 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 ExpectErrorContains(t *testing.T, err error, substr, description string)
- func ExpectNoError(t *testing.T, err error, description string)
- func ExpectNotNil(t *testing.T, value any, description string)
- func ExpectTrue(t *testing.T, condition bool, description 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 ¶
This section is empty.
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 ExpectErrorContains ¶ added in v1.12.3
ExpectErrorContains fails the test if err is nil or does not contain substr.
func ExpectNoError ¶ added in v1.12.3
ExpectNoError fails the test if err is not nil.
func ExpectNotNil ¶ added in v1.12.3
ExpectNotNil fails the test if value is nil.
func ExpectTrue ¶ added in v1.12.3
ExpectTrue fails the test if condition is false.
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.