testutil

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testutil provides utilities for Go testing including golden file management.

Index

Constants

This section is empty.

Variables

View Source
var UpdateGoldenFiles = flag.Bool("update", false, "Update golden files")

UpdateGoldenFiles is set by the -update flag to regenerate golden files

Functions

This section is empty.

Types

type GoldenFile

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

GoldenFile represents a golden file for snapshot testing

func NewGolden

func NewGolden(t *testing.T, name string) *GoldenFile

NewGolden creates a new golden file handler

func (*GoldenFile) Assert

func (g *GoldenFile) Assert(actual []byte)

Assert compares and fails the test if mismatch

func (*GoldenFile) AssertString

func (g *GoldenFile) AssertString(actual string)

AssertString compares string and fails the test if mismatch

func (*GoldenFile) Compare

func (g *GoldenFile) Compare(actual []byte) error

Compare compares the actual output against the golden file

func (*GoldenFile) CompareString

func (g *GoldenFile) CompareString(actual string) error

CompareString compares string output against golden file

func (*GoldenFile) Exists

func (g *GoldenFile) Exists() bool

Exists checks if the golden file exists

func (*GoldenFile) Path

func (g *GoldenFile) Path() string

Path returns the full path to the golden file

func (*GoldenFile) Read

func (g *GoldenFile) Read() ([]byte, error)

Read reads the golden file content

func (*GoldenFile) ReadString

func (g *GoldenFile) ReadString() (string, error)

ReadString reads the golden file as string

func (*GoldenFile) WithDir

func (g *GoldenFile) WithDir(dir string) *GoldenFile

WithDir sets a custom directory for the golden file

type GoldenMismatch

type GoldenMismatch struct {
	GoldenFile string
	Expected   string
	Actual     string
}

GoldenMismatch represents a mismatch between expected and actual output

func (*GoldenMismatch) Diff

func (m *GoldenMismatch) Diff() string

Diff returns a simple diff of expected vs actual

func (*GoldenMismatch) Error

func (m *GoldenMismatch) Error() string

Jump to

Keyboard shortcuts

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