Documentation ¶
Overview ¶
Package golden provides utilities to compare and update golden files in tests.
Index ¶
- Constants
- func CheckOrUpdate(t *testing.T, got string, options ...Option)
- func CheckOrUpdateFileTree(t *testing.T, path string, options ...Option)
- func CheckOrUpdateYAML[E any](t *testing.T, got E, options ...Option)
- func CheckValidGoldenFileName(t *testing.T, name string)
- func LoadWithUpdate(t *testing.T, data string, options ...Option) string
- func LoadWithUpdateYAML[E any](t *testing.T, got E, options ...Option) E
- func Path(t *testing.T) string
- func UpdateEnabled() bool
- type Option
Constants ¶
const ( // UpdateGoldenFilesEnv is the environment variable used to indicate go test that // the golden files should be overwritten with the current test results. UpdateGoldenFilesEnv = `TESTS_UPDATE_GOLDEN` )
Variables ¶
This section is empty.
Functions ¶
func CheckOrUpdate ¶
CheckOrUpdate compares the provided string with the content of the golden file. If the update environment variable is set, the golden file is updated with the provided string.
func CheckOrUpdateFileTree ¶
CheckOrUpdateFileTree allows comparing a goldPath directory to p. Those can be updated via the dedicated flag.
func CheckOrUpdateYAML ¶
CheckOrUpdateYAML compares the provided object with the content of the golden file. If the update environment variable is set, the golden file is updated with the provided object serialized as YAML.
func CheckValidGoldenFileName ¶
CheckValidGoldenFileName checks if the provided name is a valid golden file name.
func LoadWithUpdate ¶
LoadWithUpdate loads the element from a plaintext golden file. It will update the file if the update flag is used prior to loading it.
func LoadWithUpdateYAML ¶
LoadWithUpdateYAML load the generic element from a YAML serialized golden file. It will update the file if the update flag is used prior to deserializing it.
func UpdateEnabled ¶
func UpdateEnabled() bool
UpdateEnabled returns true if the update flag was set, false otherwise.