golden

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package golden contains objects to manage updating an search in golden files.

Index

Constants

This section is empty.

Variables

View Source
var (
	DataDir               = "testdata"
	FlagName              = "update"
	FilePerms os.FileMode = 0644
	DirPerms  os.FileMode = 0755
)
View Source
var (
	// ErrFileNotFoundInDataDir is thrown when the file to open isn't
	// found on data dir.
	ErrFileNotFoundInDataDir = errors.New("file not founded in data dir")
)
View Source
var (

	// ErrInvalidKeyPrefix it's an error returned when gold.Get is called with key starting with wrong format.
	ErrInvalidKeyPrefix = errors.New("the golden key must be prefixed by 'input.' or 'golden.'")
)
View Source
var (
	// ErrWrongKeySequence is thrown when user tries to walk through
	// invalid sequence of maps and keys.
	ErrWrongKeySequence = errors.New("invalid key sequence for golden file")
)

Functions

This section is empty.

Types

type ErrDataDirIsFile

type ErrDataDirIsFile struct {
	// contains filtered or unexported fields
}

ErrDataDirIsFile is an error thrown when the data folder, with the golden files is a file.

func NewErrDataDirIsFile

func NewErrDataDirIsFile(file string) (err *ErrDataDirIsFile)

NewErrDataDirIsFile creates an ErrDataDirIsFile with the file founded.

func (*ErrDataDirIsFile) Error

func (e *ErrDataDirIsFile) Error() (m string)

Error prints the reason for error, telling which file was found.

type Gold

type Gold struct {
	Input  interface{} `json:"input" yaml:"input"`
	Golden interface{} `json:"golden" yaml:"golden"`
}

Gold contains information about a test case on a golden file, separated in Input and Golden.

func (*Gold) Get

func (g *Gold) Get(key string) (val interface{})

Get returns value from golden file, using a json sequence of keys.

func (*Gold) Load

func (g *Gold) Load(input, gold interface{})

Load unmarshall the json into input and gold pointers received.

func (*Gold) Update

func (g *Gold) Update(values func() interface{})

Update get an struct or a map, and loads into golden part of test case, to update file with new values.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager load a golden file for a Feature, and then separates into various test cases.

func NewManager

func NewManager(feat, given string) (m *Manager)

NewManager creates a manager, using the feature tested and given context.

func (*Manager) Get

func (m *Manager) Get(i int) (g common.Golden)

Get returns the i-th test case for the feature tested in manager.

func (*Manager) NumGoldies

func (m *Manager) NumGoldies() (n int)

NumGoldies return number of test cases loaded with manager to a single feature.

func (*Manager) Update

func (m *Manager) Update()

Update uses the new values received from each test case, and then write into golden file for the feature tested.

Jump to

Keyboard shortcuts

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