gm

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataFileDiffers

func DataFileDiffers(filename string, v interface{}) (bool, error)

DataFileDiffers compares the specified value against the stored data file

func GetFilenameForTest

func GetFilenameForTest(testName string, v interface{}) (string, error)

GetFilenameForTest converts a Go test name to filename

func GitDiff

func GitDiff(path string) (string, error)

GitDiff does 'git diff' on the specified file, first changing to its directory. It returns the diff and error, if any

func Verify

func Verify(t *testing.T, data interface{})

Verify invokes VerifyNamed with empty 'name' argument

func VerifyNamed

func VerifyNamed(t *testing.T, name string, data interface{})

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

func WriteDataFile(filename string, v interface{}) error

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

func (JSONVerifier) Verify added in v1.0.1

func (v JSONVerifier) Verify(content []byte) (bool, error)

type Replacement added in v1.0.3

type Replacement struct {
	Old string
	New string
}

Replacement specifies a replacement for SubstVerifier.

type SubstVerifier added in v1.0.3

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.3

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.3

func (v SubstVerifier) Marshal() ([]byte, error)

Marshal implements Marshal method of the Verifier interface.

func (SubstVerifier) Suffix added in v1.0.3

func (v SubstVerifier) Suffix() string

Suffix implements Suffix method of the Verifier interface.

func (SubstVerifier) Verify added in v1.0.3

func (v SubstVerifier) Verify(content []byte) (bool, error)

Verify implements Verify 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.

func (YamlVerifier) Verify added in v1.0.0

func (v YamlVerifier) Verify(content []byte) (bool, error)

Verify implements Verify method of the Verifier interface.

Jump to

Keyboard shortcuts

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