should

package
v0.0.0-...-b93a6bd Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package should contains miscellaneous assertions and matchers for making the tests more expresive. The package is not named something like assert to avoid collision with existing packages.

Matchers

This package defines a Matcher interface that other modules can use for defining their own assertions. The Matcher interface is also compatible with Gomega, so any matcher from the latter should work fine.

Essential matchers can be found in the should/to package, so you can access them using to.MATCHER.

Usage

A matcher is an instance of an object that performs a check. The matcher is usually independent of the actual object being matched; if you want to apply a matcher on an actual object you can do it as follows:

should.Expect(t, ACTUAL, MATCHER)

The code above will fail the test if the ACTUAL object fails the MATCHER. If you don't want to fail the test but instead get a boolean value indicating the result of the match you can do:

should.ExpectE(t, ACTUAL, MATCHER)

Negating a matcher is also possible:

should.Refute(t, ACTUAL, MATCHER)
...or
should.Expect(t, ACTUAL, to.Not(MATCHER))

Using with Gomega

Any of the Gomega matchers should work fine:

should.Expect(t, 10, gomega.BeNumerically(">", 5)) // true

Ordering of expected and actual

Early testing frameworks originally used the order EXPECTED-ACTUAL, however, reversing the order to ACTUAL-EXPECTED allows for more fluent and expressive assertions. For instance, writing:

should.Expect(t, roses, to.Equal("red"))

Reads much better than:

should.Expect(t, to.Equal("red"), roses)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expect

func Expect(t cbtest.T, actual interface{}, matcher matcher.Matcher, labelAndArgs ...interface{})

Expect checks whenever the given actual value passes the matcher. Panics on failure (just like testify/require).

func ExpectE

func ExpectE(t cbtest.T, actual interface{}, matcher matcher.Matcher, labelAndArgs ...interface{}) bool

ExpectE checks whenever the given actual value passes the matcher. Returns boolean to indicate success or failure (just like testify/assert).

func NoError

func NoError(t cbtest.T, err interface{})

NoError fails the test if the given value is an error. Useful for ensuring no errors instead of using if err != nil, etc.

func NoErrorE

func NoErrorE(t cbtest.T, err interface{}) bool

NoErrorE checks and returns whenever the given value is not an error.

func Refute

func Refute(t cbtest.T, matcher matcher.Matcher, actual interface{}, labelAndArgs ...interface{})

Refute checks whenever the given actual value fails the matcher. Panics on failure (just like testify/require).

func RefuteE

func RefuteE(t cbtest.T, matcher matcher.Matcher, actual interface{}, labelAndArgs ...interface{}) bool

RefuteE checks whenever the given actual value fails the matcher. Returns boolean to indicate success or failure (just like testify/assert).

Types

This section is empty.

Directories

Path Synopsis
Package format includes useful functions for creating error messages.
Package format includes useful functions for creating error messages.
Package to exposes all the core matchers that can be used with the should.Expect[E] functions.
Package to exposes all the core matchers that can be used with the should.Expect[E] functions.

Jump to

Keyboard shortcuts

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