testutils

package
v1.12.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrContains

func AssertErrContains(t *testing.T, got error, contains string, ctx string)

AssertErrContains asserts that an error is non-nil and its message contains the provided substring.

func AssertErrWrappedContains

func AssertErrWrappedContains(t *testing.T, got error, want error, contains string, ctx string)

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

func AssertFileEquals(t *testing.T, dir, path, expected string)

AssertFileEquals compares the file content with the expected string.

func AssertStringContains

func AssertStringContains(t *testing.T, haystack string, subs ...string)

AssertStringContains asserts that the haystack contains all provided substrings.

func AssertStringContainsOneOf

func AssertStringContainsOneOf(t *testing.T, haystack string, options ...string)

AssertStringContainsOneOf asserts that the haystack contains at least one of the provided options.

func ExpectErrorContains added in v1.12.3

func ExpectErrorContains(t *testing.T, err error, substr, description string)

ExpectErrorContains fails the test if err is nil or does not contain substr.

func ExpectNoError added in v1.12.3

func ExpectNoError(t *testing.T, err error, description string)

ExpectNoError fails the test if err is not nil.

func ExpectNotNil added in v1.12.3

func ExpectNotNil(t *testing.T, value any, description string)

ExpectNotNil fails the test if value is nil.

func ExpectTrue added in v1.12.3

func ExpectTrue(t *testing.T, condition bool, description string)

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

func RunNameCases(t *testing.T, cases []NameCase, run func(t *testing.T, c NameCase))

RunNameCases runs the provided function for each NameCase with parallel subtests.

func RunTestMainWithSnapshotCleanup

func RunTestMainWithSnapshotCleanup(m *testing.M)

RunTestMainWithSnapshotCleanup runs the standard TestMain pattern with snapshot cleanup. Shared across packages that only need snapshot cleanup (non command-specific logic).

func SetupExistingFile

func SetupExistingFile(t *testing.T, filename string) (string, string, string)

SetupExistingFile creates a temporary directory and an existing config file with default placeholder content, returning the directory, file path, and content string.

Types

type NameCase

type NameCase struct {
	Name         string
	InputName    string
	ExpectedName string
}

NameCase represents a common test case shape for commands that accept an optional name and default to a configured name when empty.

func DefaultNameCases

func DefaultNameCases(defaultCfgName string) []NameCase

DefaultNameCases returns the standard two cases used throughout the repo: 1) explicit name; 2) empty name falls back to default/cfg name.

Jump to

Keyboard shortcuts

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