testutility

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanSnapshots

func CleanSnapshots(m *testing.M)

CleanSnapshots ensures that snapshots are relevant and sorted for consistency

func IsAcceptanceTest

func IsAcceptanceTest() bool

Access to environment variable that toggles acceptance testing execution paths Acceptance testing is "On" only when var set to "true"

func LoadJSONFixture

func LoadJSONFixture[V any](t *testing.T, path string) V

LoadJSONFixture returns the contents of the fixture file parsed as JSON

func LoadJSONFixtureWithWindowsReplacements

func LoadJSONFixtureWithWindowsReplacements[V any](
	t *testing.T,
	path string,
	replacements map[string]string,
) V

LoadJSONFixtureWithWindowsReplacements returns the contents of the fixture file parsed as JSON after applying any replacements if running on Windows

func NormalizeJSON

func NormalizeJSON(t *testing.T, data any) string

NormalizeJSON applies a series of normalizes to a buffer after being marshalled as JSON

func NormalizeStdStream

func NormalizeStdStream(t *testing.T, std *bytes.Buffer) string

NormalizeStdStream applies a series of normalizes to the buffer from a std stream like stdout and stderr

func Skip

func Skip(t *testing.T, args ...any)

Skip is equivalent to t.Log followed by t.SkipNow, but allows tracking of what snapshots are skipped so that they're not marked as obsolete

func SkipIfNotAcceptanceTesting

func SkipIfNotAcceptanceTesting(t *testing.T, reason string)

AcceptanceTests marks this test function as a extended that require additional dependencies automatically skipped unless running in a CI environment

func ValueIfOnWindows

func ValueIfOnWindows(win, or string) string

Types

type Snapshot

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

func NewSnapshot

func NewSnapshot() Snapshot

NewSnapshot creates a snapshot that can be passed around within tests

func (Snapshot) MatchJSON

func (s Snapshot) MatchJSON(t *testing.T, got any)

MatchJSON asserts the existing snapshot matches what was gotten in the test, after being marshalled as JSON

func (Snapshot) MatchText

func (s Snapshot) MatchText(t *testing.T, got string)

MatchText asserts the existing snapshot matches what was gotten in the test

func (Snapshot) WithCRLFReplacement

func (s Snapshot) WithCRLFReplacement() Snapshot

WithCRLFReplacement adds a Windows replacement for "\r\n" to "\n".

func (Snapshot) WithJSONNormalization

func (s Snapshot) WithJSONNormalization() Snapshot

WithJSONNormalization applies JSON normalization to the snapshot to errors and paths

func (Snapshot) WithWindowsReplacements

func (s Snapshot) WithWindowsReplacements(replacements map[string]string) Snapshot

WithWindowsReplacements adds a map of strings with values that they should be replaced within before comparing the snapshot when running on Windows

Jump to

Keyboard shortcuts

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