Documentation
¶
Overview ¶
Package verifier provides a set of APIs that tie in to the Go testing system and allow snapshot testing.
Example Usage ¶
To verify validity of a struct in a standard test file called function:
import (
"testing"
"github.com/VerifyTests/Verify.Go/verifier"
)
func TestVerifyingStructs(t *testing.T) {
var person = Person{
ID: "ebced679-45d3-4653-8791-3d969c4a986c",
Title: Mr,
FamilyName: "Smith",
GivenNames: "John",
Dob: time.Date(2022, 02, 01, 1, 2, 3, 4, time.Local),
Spouse: "Jill",
Address: Address{
Street: "4 Puddle Lane",
Country: &country,
},
Children: []string{"Sam", "Mary"},
}
verifier.Verify(t, person)
}
When the test is initially run will fail. If a diff tool is detected it will display the diff. To verify the result:
- Use the diff tool to accept the changes, or
- Manually copy the text to the new file
After verifications, all `*.verified.*` files should be committed to source control and all `*.received.*` files should be excluded from source control.
VerifySettings ¶
Verify allow configuring the verification process by using VerifySettings.
All assertion functions take, as the first argument, the `*testing.T` object provided by the testing framework. This allows the assertion funcs to write the failings and other details to the correct place.
Every assertion function also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.
Index ¶
- func Verify(t testingT, target interface{})
- func VerifyWithSetting(t testingT, settings VerifySettings, target interface{})
- type AfterVerifyFunc
- type BeforeVerifyFunc
- type CleanupFunc
- type CompareResult
- type EqualFiles
- type EqualityResult
- type FileAppenderFunc
- type FileConventionFunc
- type FileEquality
- type FilePair
- type FirstVerifyFunc
- type InstanceScrubber
- type JSONAppenderFunc
- type NewFiles
- type NotEqualFilePair
- type NotEqualFiles
- type RemoveLineFunc
- type ReplaceLineFunc
- type StreamComparerFunc
- type StringComparerFunc
- type Target
- type Verifier
- type VerifyDeleteFunc
- type VerifyMismatchFunc
- type VerifySettings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Verify ¶
func Verify(t testingT, target interface{})
Verify verifies the passed target with the default settings.
func VerifyWithSetting ¶
func VerifyWithSetting(t testingT, settings VerifySettings, target interface{})
VerifyWithSetting verifies the passed target with the provided settings.
Types ¶
type AfterVerifyFunc ¶
type AfterVerifyFunc func()
AfterVerifyFunc a function to run after verification
type BeforeVerifyFunc ¶
type BeforeVerifyFunc func()
BeforeVerifyFunc a function to run before verification
type CompareResult ¶
CompareResult specifies comparison results with an optional message
type EqualFiles ¶
type EqualFiles []FilePair
EqualFiles a slice of FilePair that contains equal files
type EqualityResult ¶
type EqualityResult struct {
Equality FileEquality
Message string
}
EqualityResult specifies file content equality with an optional message
type FileConventionFunc ¶
FileConventionFunc provides a unique file and directory for the test
type FileEquality ¶
type FileEquality int
FileEquality file content equality
const ( //FileEqual designates files with equal contents FileEqual FileEquality = iota //FileNotEqual designates files with different contents FileNotEqual //FileNew designates new files FileNew )
type FilePair ¶
type FilePair struct {
Extension string
ReceivedPath string
VerifiedPath string
ReceivedName string
VerifiedName string
Name string
IsText bool
}
FilePair information for a file being compared containing received and verified files.
type FirstVerifyFunc ¶
type FirstVerifyFunc func(file FilePair)
FirstVerifyFunc a function to run on first verification
type InstanceScrubber ¶
InstanceScrubber a function that scrubs the input target and returns the scrubbed version
type NotEqualFilePair ¶
NotEqualFilePair designates a non-equal file information with an optional message
type NotEqualFiles ¶
type NotEqualFiles []NotEqualFilePair
NotEqualFiles a slice of NotEqualFilePair that contains non-equal files
type RemoveLineFunc ¶
RemoveLineFunc decides if a line from the target should be removed
type ReplaceLineFunc ¶
ReplaceLineFunc replaces a line from the target the the output
type StreamComparerFunc ¶
type StreamComparerFunc func(received, verified []byte) CompareResult
StreamComparerFunc a function that compares stream contents of received and verified files and returns the CompareResult
type StringComparerFunc ¶
type StringComparerFunc func(received, verified string) CompareResult
StringComparerFunc a function that compares string content of received and verified files and returns the CompareResult
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target contains the information about the underlying target being verified
func (*Target) GetExtension ¶
GetExtension returns the extension of the target
func (*Target) GetStreamData ¶
GetStreamData returns the underlying target data as a stream
func (*Target) GetStringBuilderData ¶
GetStringBuilderData returns the underlying target data as strings.Builder
func (*Target) GetStringData ¶
GetStringData returns the underlying target data as a string
func (*Target) IsStringBuilder ¶
IsStringBuilder checks if the target is a strings.Builder type.
type Verifier ¶
type Verifier interface {
Verify(target interface{})
}
Verifier is the main interface for verification process.
func NewVerifier ¶
func NewVerifier(t testingT, settings VerifySettings) Verifier
NewVerifier creates a new Verifier with the associated VerifySettings settings
type VerifyDeleteFunc ¶
type VerifyDeleteFunc func(file string)
VerifyDeleteFunc a function to run before deletion of a file
type VerifyMismatchFunc ¶
VerifyMismatchFunc a function to run when a content mismatch happens
type VerifySettings ¶
type VerifySettings interface {
AutoVerify()
DisableDiff()
UseStrictJSON()
DontScrubGuids()
DontScrubTimes()
UniqueForArchitecture()
UniqueForOperatingSystem()
UniqueForRuntime()
UseDirectory(directory string)
UseExtension(extension string)
ScrubMachineName()
AddScrubber(fun InstanceScrubber)
AddScrubberForExtension(extension string, fun InstanceScrubber)
ScrubLinesContainingAnyCase(stringToMatch ...string)
ScrubLinesContaining(stringToMatch ...string)
ScrubInlineGuids()
ScrubLines(fun RemoveLineFunc)
ScrubLinesWithReplace(fun ReplaceLineFunc)
ScrubEmptyLines()
UseStreamComparer(fun StreamComparerFunc)
UseStringComparer(fun StringComparerFunc)
OnAfterVerify(fun AfterVerifyFunc)
OnBeforeVerify(fun BeforeVerifyFunc)
OnFirstVerify(fun FirstVerifyFunc)
OnVerifyMismatch(fun VerifyMismatchFunc)
OnVerifyDelete(fun VerifyDeleteFunc)
OmitContentFromError()
TestCase(name string)
}
VerifySettings provides customization for the Verify process.
func NewSettings ¶
func NewSettings() VerifySettings
NewSettings returns a new default instance of the VerifySettings