gerrors

package module
v0.0.0-...-c8fa558 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2017 License: MIT Imports: 5 Imported by: 0

README

Go Report Card

Gomega matchers for other error packages

This package provides Gomega matchers to write assertions against errors:

This package is needed to address deficiencies in gomega's default MatchError()

MatchWrappedError()

Verifies that an error matches the expected one, including errors that have been wrapped by a context.

import (
  "errors"
  perrors "github.com/pkg/errors"
  
  . "github.com/chendrix/gerrors"
)

err := errors.New("some error")
err2 := perrors.Wrap(err, "read failed")

Expect(err).To(MatchError("some error")) // Pass
Expect(err2).To(MatchError("some error")) // Fail!

Expect(err).To(MatchWrappedError("some error")) // Pass
Expect(err2).To(MatchWrappedError("some error")) // Pass

ContainMatchedError()

Verifies that an error is included in a go-multierror error.

import (
  "errors"
   "github.com/hashicorp/go-multierror"
  
  . "github.com/chendrix/gerrors"
)

var result error 
err := errors.New("some error")

result = multierror.Append(result, err)

Expect(err).To(MatchError("some error")) // Pass
Expect(result).To(MatchError("some error")) // Fail!

Expect(err).To(ContainWrappedError("some error")) // Pass
Expect(result).To(ContainWrappedError("some error")) // Pass

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainMatchedError

func ContainMatchedError(expected interface{}) types.GomegaMatcher

func MatchWrappedError

func MatchWrappedError(expected interface{}) types.GomegaMatcher

Types

type Causer

type Causer interface {
	Cause() error
}

type ContainMatchedErrorMatcher

type ContainMatchedErrorMatcher struct {
	Expected interface{}
}

func (*ContainMatchedErrorMatcher) FailureMessage

func (matcher *ContainMatchedErrorMatcher) FailureMessage(actual interface{}) string

func (*ContainMatchedErrorMatcher) Match

func (matcher *ContainMatchedErrorMatcher) Match(actual interface{}) (bool, error)

func (*ContainMatchedErrorMatcher) NegatedFailureMessage

func (matcher *ContainMatchedErrorMatcher) NegatedFailureMessage(actual interface{}) string

type MatchWrappedErrorMatcher

type MatchWrappedErrorMatcher struct {
	Expected interface{}
}

func (*MatchWrappedErrorMatcher) FailureMessage

func (matcher *MatchWrappedErrorMatcher) FailureMessage(actual interface{}) string

func (*MatchWrappedErrorMatcher) Match

func (matcher *MatchWrappedErrorMatcher) Match(actual interface{}) (bool, error)

func (*MatchWrappedErrorMatcher) NegatedFailureMessage

func (matcher *MatchWrappedErrorMatcher) NegatedFailureMessage(actual interface{}) string

Jump to

Keyboard shortcuts

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