Documentation ¶
Index ¶
- func DataFileDiffers(filename string, v interface{}) (bool, error)
- func GetFilenameForTest(testName string, v interface{}) (string, error)
- func GitDiff(path string) (string, error)
- func Verify(t *testing.T, data interface{})
- func VerifyNamed(t *testing.T, name string, data interface{})
- func WriteDataFile(filename string, v interface{}) error
- type JSONVerifier
- type Replacement
- type SubstVerifier
- type Verifier
- type YamlVerifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DataFileDiffers ¶
DataFileDiffers compares the specified value against the stored data file
func GetFilenameForTest ¶
GetFilenameForTest converts a Go test name to filename
func GitDiff ¶
GitDiff does 'git diff' on the specified file, first changing to its directory. It returns the diff and error, if any
func VerifyNamed ¶
VerifyNamed generates a file name based on current test name and the 'name' argument and compares its contents in git index (i.e. staged or committed if the changes are staged for the file) to that of of 'data' argument. The test will fail if the data differs. In this case the target file is updated and the user must stage or commit the changes to make the test pass. If data is string or []byte, it's compared directly to the contents of the file (the data are supposed to be human-readable and easily diffable). If data implements Verifier interface, the comparison is done by invoking it's Verify method on the contents of the file. Otherwise, the comparison is done based on JSON representation of the data ignoring any changes in JSON formatting and any changes introduced by the encoding/json marshalling mechanism. If data implements Verifier interface, the updated contents of the data file is generated using its Marshal() method. The suffix of the data file name is generated based on the data argument, too. For text content, ".out.txt" suffix is used. For json content, the suffix is ".out.json". For Verifier type, the suffix is ".out" concatenated with the value of the Suffix() method.
func WriteDataFile ¶
WriteDataFile serializes the specified value into a data file
Types ¶
type JSONVerifier ¶ added in v1.0.1
type JSONVerifier struct {
// contains filtered or unexported fields
}
func NewJSONVerifier ¶ added in v1.0.1
func NewJSONVerifier(data interface{}) JSONVerifier
func (JSONVerifier) Marshal ¶ added in v1.0.1
func (v JSONVerifier) Marshal() ([]byte, error)
func (JSONVerifier) Suffix ¶ added in v1.0.1
func (v JSONVerifier) Suffix() string
type Replacement ¶ added in v1.0.2
Replacement specifies a replacement for SubstVerifier.
type SubstVerifier ¶ added in v1.0.2
type SubstVerifier struct {
// contains filtered or unexported fields
}
SubstVerifier wraps another verifier and replaces the specified substrings in the data it generates.
func NewSubstVerifier ¶ added in v1.0.2
func NewSubstVerifier(next Verifier, replacements []Replacement) SubstVerifier
NewSubstVerifier makes a SubstVerifier that wraps another verifier and does the specified replacements.
func (SubstVerifier) Marshal ¶ added in v1.0.2
func (v SubstVerifier) Marshal() ([]byte, error)
Marshal implements Marshal method of the Verifier interface.
func (SubstVerifier) Suffix ¶ added in v1.0.2
func (v SubstVerifier) Suffix() string
Suffix implements Suffix method of the Verifier interface.
type Verifier ¶ added in v1.0.0
type Verifier interface { // Suffix returns the suffix for the file name of the Golden Master // data file for this value. Suffix() string // Marshal generates the contents of the Golden Master data file. Marshal() ([]byte, error) // Verify returns true if the contents can be considered // the same as the value of the Verifier. It should not return // an error if content is invalid. Verify(content []byte) (bool, error) }
Verifier describes a type that can verify its contents against a Golden Master data file and also generate the contents of such file
type YamlVerifier ¶ added in v1.0.0
type YamlVerifier struct {
// contains filtered or unexported fields
}
YamlVerifier verifies the data using YAML representation.
func NewYamlVerifier ¶ added in v1.0.0
func NewYamlVerifier(data interface{}) YamlVerifier
NewYamlVerifier makes a YamlVerifier with the specified content.
func (YamlVerifier) Marshal ¶ added in v1.0.0
func (v YamlVerifier) Marshal() ([]byte, error)
Marshal implements Marshal method of the Verifier interface.
func (YamlVerifier) Suffix ¶ added in v1.0.0
func (v YamlVerifier) Suffix() string
Suffix implements Suffix method of the Verifier interface.