goldenfile

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package goldenfile allows you to assert that a function that generates a file generates the exact file you expect.

Golden files are stored in testdata/<test-name>.golden they are written when the `-update` flag is used with `go test`, or when the test is run with UPDATE_TESTDATE=true.

Without the `-update` flag, files are witten to a temp directory and compared with the golden files themselves.

This is based on the talk Advanced Go Testing by @mitchellh, and is different from other golden file libraries because it allows access to the underlying file, not just the ability to write a set of bytes to a file. This allows writing tests that include code you do not control that requires direct access to a file (e.g. github.com/sethvargo/go-githubactions.SetEnv).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(t *testing.T, fn FileAction)

Do allows you to run a function to write to the actual file. It asserts that the actual file written matches the golden file. If updating it also updates the golden file.

Types

type FileAction

type FileAction func(got *os.File)

FileAction is a function that writes to the 'got' file.

type GF

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

Jump to

Keyboard shortcuts

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