golden

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package golden provides tools for comparing large mutli-line strings.

Golden files are files in the ./testdata/ subdirectory of the package under test.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert deprecated

func Assert(t assert.TestingT, actual string, filename string, msgAndArgs ...interface{}) bool

Assert compares the actual content to the expected content in the golden file. If the `-test.update-golden` flag is set then the actual content is written to the golden file. Returns whether the assertion was successful (true) or not (false). This is equivalent to assert.Check(t, String(actual, filename))

Deprecated: In a future version this function will change to use assert.Assert instead of assert.Check to be consistent with other assert functions. Use assert.Check(t, String(actual, filename) if you want to preserve the current behaviour.

Example
package main

import (
	"testing"

	"github.com/gotestyourself/gotestyourself/golden"
)

var t = &testing.T{}

func main() {
	golden.Assert(t, "foo", "foo-content.golden")
}
Output:

func AssertBytes deprecated

func AssertBytes(
	t assert.TestingT,
	actual []byte,
	filename string,
	msgAndArgs ...interface{},
) bool

AssertBytes compares the actual result to the expected result in the golden file. If the `-test.update-golden` flag is set then the actual content is written to the golden file. Returns whether the assertion was successful (true) or not (false) This is equivalent to assert.Check(t, Bytes(actual, filename))

Deprecated: In a future version this function will change to use assert.Assert instead of assert.Check to be consistent with other assert functions. Use assert.Check(t, Bytes(actual, filename) if you want to preserve the current behaviour.

Example
package main

import (
	"testing"

	"github.com/gotestyourself/gotestyourself/golden"
)

var t = &testing.T{}

func main() {
	golden.AssertBytes(t, []byte("foo"), "foo-content.golden")
}
Output:

func Bytes added in v1.3.0

func Bytes(actual []byte, filename string) cmp.Comparison

Bytes compares actual to the contents of filename and returns success if the bytes are equal. If the `-test.update-golden` flag is set then the actual content is written to the golden file.

func Get

func Get(t assert.TestingT, filename string) []byte

Get returns the contents of the file in ./testdata

func Path

func Path(filename string) string

Path returns the full path to a file in ./testdata

func String added in v1.3.0

func String(actual string, filename string) cmp.Comparison

String compares actual to the contents of filename and returns success if the strings are equal. If the `-test.update-golden` flag is set then the actual content is written to the golden file.

Any \r\n substrings in actual are converted to a single \n character before comparing it to the expected string. When updating the golden file the normalized version will be written to the file. This allows Windows to use the same golden files as other operating systems.

Example
package main

import (
	"testing"

	"github.com/gotestyourself/gotestyourself/assert"
	"github.com/gotestyourself/gotestyourself/golden"
)

var t = &testing.T{}

func main() {
	assert.Assert(t, golden.String("foo", "foo-content.golden"))
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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