erkmock

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package erkmock allows creating erk errors to be returned from mocked interfaces. Without using this package, it's possible to get false positive strict mode errors.

Example:

someMockedFunction.Returns(erkmock.From(store.ErrItemNotFound))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func For

func For(kind erk.Kind) error

For a given erk kind, create a mock error.

func From

func From(err error) error

From a given erk error, create a mock error. This will panic if the provided error does not satisfy erk.Erkable.

Types

type Mock

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

Mock erk.Erkable implementation. Setting parameters on a mock modify the mock in place. Thus, it is recommended to create a new mock instead of using the same one multiple times.

func (*Mock) Error

func (m *Mock) Error() string

Error returns the error kind, message, and parameters formatted as a string.

func (*Mock) Export

func (m *Mock) Export() erk.ExportedErkable

Export the mock error.

func (*Mock) ExportRawMessage added in v0.5.6

func (m *Mock) ExportRawMessage() string

ExportRawMessage without executing the template.

func (*Mock) Is

func (m *Mock) Is(err error) bool

Is implements the Go 1.13+ Is interface for use with errors.Is.

If the mock has no message set, only the error kinds are compared. Otherwise, the error kinds and messages are compared.

func (*Mock) Kind

func (m *Mock) Kind() erk.Kind

Kind returns the mock error kind.

func (*Mock) Params

func (m *Mock) Params() erk.Params

Params set on the mock error.

func (*Mock) SetMessage added in v0.5.6

func (m *Mock) SetMessage(message string)

SetMessage on the mock.

func (*Mock) WithParams

func (m *Mock) WithParams(params erk.Params) error

WithParams modifies the mock error params in place (instead of on a clone). Note that this behavior is different, since it allows checking on the original mock if any errors were set.

Jump to

Keyboard shortcuts

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