verifier

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 23 Imported by: 0

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

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 CleanupFunc

type CleanupFunc func()

CleanupFunc cleanup function

type CompareResult

type CompareResult struct {
	IsEqual bool
	Message string
}

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 FileAppenderFunc

type FileAppenderFunc func() *Target

FileAppenderFunc returns a target

type FileConventionFunc

type FileConventionFunc func(uniqueness string) (fileNamePrefix string, directory string)

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

type InstanceScrubber func(target string) string

InstanceScrubber a function that scrubs the input target and returns the scrubbed version

type JSONAppenderFunc

type JSONAppenderFunc func() *toAppend

JSONAppenderFunc returns an appender

type NewFiles

type NewFiles []FilePair

NewFiles a slice of FilePair that contains new files

type NotEqualFilePair

type NotEqualFilePair struct {
	File    FilePair
	Message string
}

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

type RemoveLineFunc func(string) bool

RemoveLineFunc decides if a line from the target should be removed

type ReplaceLineFunc

type ReplaceLineFunc func(string) string

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

func (t *Target) GetExtension() string

GetExtension returns the extension of the target

func (*Target) GetStreamData

func (t *Target) GetStreamData() []byte

GetStreamData returns the underlying target data as a stream

func (*Target) GetStringBuilderData

func (t *Target) GetStringBuilderData() *strings.Builder

GetStringBuilderData returns the underlying target data as strings.Builder

func (*Target) GetStringData

func (t *Target) GetStringData() string

GetStringData returns the underlying target data as a string

func (*Target) IsStream

func (t *Target) IsStream() bool

IsStream checks if the target is a binary data

func (*Target) IsString

func (t *Target) IsString() bool

IsString checks if the target is a string data

func (*Target) IsStringBuilder

func (t *Target) IsStringBuilder() bool

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

type VerifyMismatchFunc func(file FilePair, message string)

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

Jump to

Keyboard shortcuts

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