xtest

package
v0.0.0-...-5cfaba6 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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

func JSONMarshalIndentedString(t *testing.T, str string) string

JSONMarshalIndentedString returns an indentend JSON string.

func JSONMarshalIndentedValue

func JSONMarshalIndentedValue(t *testing.T, value any) string

JSONMarshalIndentedValue returns an indentend JSON string.

func MustEqualFile

func MustEqualFile(t *testing.T, expectedFilePath, data string)

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

func MustReadFile(t testing.TB, fileName string, msgAndArgs ...any) string

MustReadFile reads and returns the file contents as string or fails the test if an error occurs.

func RegexpEscapedPatternWithTypes

func RegexpEscapedPatternWithTypes(t *testing.T, input string) *regexp.Regexp

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

func StructMustEqualJSONFile(t *testing.T, expectedFilePath string, data any)

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.

Jump to

Keyboard shortcuts

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