Documentation ¶
Index ¶
- Constants
- func GoldenFilePath(t *testing.T, root string, fileOptions ...GoldenFilePathOption) string
- func JSONMarshalIndentedString(t *testing.T, str string) string
- func JSONMarshalIndentedValue(t *testing.T, value any) string
- func MustEqualFile(t *testing.T, expectedFilePath, data string)
- func MustReadFile(t testing.TB, fileName string, msgAndArgs ...any) string
- func RegexpEscapedPatternWithTypes(t *testing.T, input string) *regexp.Regexp
- func StructMustEqualJSONFile(t *testing.T, expectedFilePath string, data any)
- type GoldenFilePathOption
Constants ¶
const ( Text = "txt" YAML = "yaml" JSON = "json" )
Variables ¶
This section is empty.
Functions ¶
func GoldenFilePath ¶
func GoldenFilePath(t *testing.T, root string, fileOptions ...GoldenFilePathOption) string
GoldenFilePath constructs the file path for a golden test file based on the test name, test file, and id.
func JSONMarshalIndentedString ¶
JSONMarshalIndentedString returns an indentend JSON string.
func JSONMarshalIndentedValue ¶
JSONMarshalIndentedValue returns an indentend JSON string.
func MustEqualFile ¶
MustEqualFile compares pass in data to a recorded file. If updateGoldenFiles flag is enabled, the recorded json is updated before the comparison. Ex: go test ./src/to/tests/... -update-golden-files or Ex: UPDATE_GOLDEN_FILES=1 go test ./src/to/tests/...
func MustReadFile ¶
MustReadFile reads and returns the file contents as string or fails the test if an error occurs.
func RegexpEscapedPatternWithTypes ¶
RegexpEscapedPatternWithTypes returns a regexp pattern with specific type aliases replaced with their regexp patterns and all other characters escaped. The supported types are:
- string: $uuid pattern: "?[a-zA-Z0-9-]{32,36}"?
func StructMustEqualJSONFile ¶
StructMustEqualJSONFile compares passed in data to recorded json. If updateGoldenFiles flag is enabled, the recorded json is updated before the comparison. Ex: go test ./src/to/tests/... --update-golden-files
Types ¶
type GoldenFilePathOption ¶
type GoldenFilePathOption func(options *goldenFilePathOpts)
GoldenFilePathOption specifies options for creating golden test files.
func TextGoldenFile ¶
func TextGoldenFile() GoldenFilePathOption
TextGoldenFile specifies that the golden test file path should be a text file.
func WithID ¶
func WithID(id string) GoldenFilePathOption
WithID specifies a unique id as part of the suffix for the golden test file.
func YAMLGoldenFile ¶
func YAMLGoldenFile() GoldenFilePathOption
YAMLGoldenFile specifies that the golden test file path should be a Yaml file.