gotest.tools: gotest.tools/assert/cmp Index | Files

package cmp

import "gotest.tools/assert/cmp"

Package cmp provides Comparisons for Assert and Check

Index

Package Files

compare.go result.go

Variables

var ResultSuccess = result{success: true}

ResultSuccess is a constant which is returned by a ComparisonWithResult to indicate success.

type Comparison Uses

type Comparison func() Result

Comparison is a function which compares values and returns ResultSuccess if the actual value matches the expected value. If the values do not match the Result will contain a message about why it failed.

func Contains Uses

func Contains(collection interface{}, item interface{}) Comparison

Contains succeeds if item is in collection. Collection may be a string, map, slice, or array.

If collection is a string, item must also be a string, and is compared using strings.Contains(). If collection is a Map, contains will succeed if item is a key in the map. If collection is a slice or array, item is compared to each item in the sequence using reflect.DeepEqual().

func DeepEqual Uses

func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison

DeepEqual compares two values using google/go-cmp (http://bit.do/go-cmp) and succeeds if the values are equal.

The comparison can be customized using comparison Options. Package https://godoc.org/gotest.tools/assert/opt provides some additional commonly used Options.

func Equal Uses

func Equal(x, y interface{}) Comparison

Equal succeeds if x == y. See assert.Equal for full documentation.

func Error Uses

func Error(err error, message string) Comparison

Error succeeds if err is a non-nil error, and the error message equals the expected message.

func ErrorContains Uses

func ErrorContains(err error, substring string) Comparison

ErrorContains succeeds if err is a non-nil error, and the error message contains the expected substring.

func ErrorType Uses

func ErrorType(err error, expected interface{}) Comparison

ErrorType succeeds if err is not nil and is of the expected type.

Expected can be one of: a func(error) bool which returns true if the error is the expected type, an instance of (or a pointer to) a struct of the expected type, a pointer to an interface the error is expected to implement, a reflect.Type of the expected struct or interface.

func Len Uses

func Len(seq interface{}, expected int) Comparison

Len succeeds if the sequence has the expected length.

func Nil Uses

func Nil(obj interface{}) Comparison

Nil succeeds if obj is a nil interface, pointer, or function.

Use NilError() for comparing errors. Use Len(obj, 0) for comparing slices, maps, and channels.

func Panics Uses

func Panics(f func()) Comparison

Panics succeeds if f() panics.

type Result Uses

type Result interface {
    Success() bool
}

Result of a Comparison.

func ResultFailure Uses

func ResultFailure(message string) Result

ResultFailure returns a failed Result with a failure message.

func ResultFailureTemplate Uses

func ResultFailureTemplate(template string, data map[string]interface{}) Result

ResultFailureTemplate returns a Result with a template string and data which can be used to format a failure message. The template may access data from .Data, the comparison args with the callArg function, and the formatNode function may be used to format the call args.

func ResultFromError Uses

func ResultFromError(err error) Result

ResultFromError returns ResultSuccess if err is nil. Otherwise ResultFailure is returned with the error message as the failure message.

Package cmp imports 9 packages (graph) and is imported by 10 packages. Updated 2018-07-28. Refresh now. Tools for package owners.