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 ¶
FileAction is a function that writes to the 'got' file.