testutils

package
v0.0.0-...-76418ef Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrorIs

func AssertErrorIs(t *testing.T, expected, actual error, message string)

AssertErrorIs asserts actual contains expected via errors.Is(). Special handling for testutils.ExpectedOneOfErr: succeeds if *any* listed error matches.

Usage example:

var errs testutils.ExpectedOneOfErr
errs = append(errs, ErrInvalidEmail, ErrMissingField)
testutils.AssertErrorIs(t, errs, apiErr, "should include validation error")

func CheckError

func CheckError(t *testing.T, name string, expectedErr error, actualErr error)

func CheckErrors

func CheckErrors(t *testing.T, name string, expectedErrs []error, actualErr error)

func CheckOutput

func CheckOutput(t *testing.T, name string,
	expected any, actual any,
)

func CheckOutputWithError

func CheckOutputWithError(t *testing.T, name string,
	expected any, expectedErr error,
	actual any, actualErr error,
)

CheckOutputWithError verifies both output values and returned errors produced by a test case.

Special handling:

  • If expectedErr is nil, any actual error fails the test.
  • If expectedErr is a StrError, comparison allows either:
  • errors.Is match, OR
  • substring match of the error message.
  • Otherwise, strict errors.Is comparison is required.

Types

type ExpectedOneOfErr

type ExpectedOneOfErr []error

ExpectedOneOfErr is a testutils wrapper for multiple errors that signals AssertErrorIs should check if *any* contained error matches the actual error. Enables flexible multi-error assertions.

func (ExpectedOneOfErr) Error

func (e ExpectedOneOfErr) Error() string

type FileData

type FileData []byte

func DataFromFile

func DataFromFile(t *testing.T, testFileName string) FileData

DataFromFile is used for server mocking. Files must be located under ./test directory relative to the test runner.

type ParallelRunner

type ParallelRunner[C any] struct {
	FilePath  string
	TestTitle string
	Function  func(ctx context.Context, conn C, filePath string) (string, error)
}

type ParallelRunners

type ParallelRunners[C any] []ParallelRunner[C]

func (ParallelRunners[C]) Run

func (r ParallelRunners[C]) Run(ctx context.Context, conn C) []string

Run will execute test suites in parallel. Note: filePath must be neighbouring to the caller of this method.

type StrError

type StrError struct {
	// contains filtered or unexported fields
}

StrError is a marker error type used in tests to indicate that an error should primarily be compared by its string content.

Unlike ordinary errors that rely strictly on errors.Is matching, StrError allows fallback comparison via substring matching of the error message. This is useful when:

  • the concrete error type is unstable or wrapped differently
  • dynamic context is added to the error
  • only the semantic message matters for the test

Test-helpers interpret this type as a signal that textual comparison is acceptable when strict error identity does not match.

func StringError

func StringError(text string) StrError

StringError creates a StrError from a plain string.

Instead of asserting exact error identity, the testing utilities will allow message-based comparison when this marker type is used.

func (StrError) Error

func (e StrError) Error() string

Jump to

Keyboard shortcuts

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