test

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package test is a set of helper functions of tests

Index

Constants

View Source
const FixturePath = "./testdata"

FixturePath is the path of the fixtures

Variables

This section is empty.

Functions

func AssertInput

func AssertInput(t *testing.T, input, got, exp interface{})

AssertInput calls AssertLabel, but sets the context based on input

func AssertLabel

func AssertLabel(t *testing.T, label string, got, exp interface{})

AssertLabel does a simple assertion

func AssertLabelString

func AssertLabelString(label string, got, exp interface{}) string

AssertLabelString returns a string format for assertions

func DiffString

func DiffString(label string, got, exp, diff interface{}) string

DiffString returns a string format for diffs

func EnvSetting

func EnvSetting(t *testing.T, envKey, defaultValue string, callDefaultSettings func() string)

EnvSetting is a standard test for environment variables's interaction with DefaultSettings()

func IfError

func IfError(t *testing.T, err error)

IfError calls t.Error if err != nil

func PrintLogEntries

func PrintLogEntries(t *testing.T, hook *logTest.Hook)

PrintLogEntries prints all the log entries of the hook

func RandSeed

func RandSeed()

RandSeed sets the rand.Seed

func ReadFixture

func ReadFixture(t *testing.T, filename string) []byte

ReadFixture reads the fixture given the filename

func SafeLogEntries

func SafeLogEntries(hook *logTest.Hook) bool

SafeLogEntries returns true if all log entries of hook are "safe" (not warnings or more dangerous)

func SandboxDir

func SandboxDir(t *testing.T, originalPath string) (string, func())

SandboxDir sets up a TempDir for a sandbox

func Time

func Time(i int) time.Time

Time returns a standard time to test with

func TimeDiff

func TimeDiff(callback func()) time.Duration

TimeDiff finds the time difference between the callack

func UpdateFixtureFlag

func UpdateFixtureFlag() *bool

UpdateFixtureFlag checks for the -update flag for go test to update the fixtures

func WriteFixture

func WriteFixture(t *testing.T, filename string, data []byte)

WriteFixture writes the fixture given the filename

Types

type Context

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

Context represents a context of a test loop

func NewContext

func NewContext() *Context

NewContext returns a new Context

func (*Context) DiffString

func (context *Context) DiffString(label string, got, exp, diff interface{}) string

DiffString is String() for diffs

func (*Context) FieldsString

func (context *Context) FieldsString() string

FieldsString returns the fields of the context as a sorted string of key1=value1 key2=value2 ...

func (*Context) GotExpString

func (context *Context) GotExpString(label string, got, exp interface{}) string

GotExpString is String() for assertions

func (*Context) SetFields

func (context *Context) SetFields(fields ContextFields) *Context

SetFields sets the fields of Context

func (*Context) String

func (context *Context) String(i interface{}) string

String returns the string representation of i, prefixed with the FieldsString()

func (*Context) Stringf

func (context *Context) Stringf(format string, args ...interface{}) string

Stringf is a formatted version of String()

type ContextFields

type ContextFields map[string]interface{}

ContextFields is the fields of the context

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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