gstruct

package
v0.0.0-...-f620936 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2017 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ignore

func Ignore() types.GomegaMatcher

Ignore ignores the actual value and always succeeds.

Expect(nil).To(Ignore())
Expect(true).To(Ignore())

func MatchAllElements

func MatchAllElements(identifier Identifier, elements Elements) types.GomegaMatcher

MatchAllElements succeeds if every element of a slice matches the element matcher it maps to through the id function, and every element matcher is matched.

Expect([]string{"a", "b"}).To(MatchAllElements(idFn, matchers.Elements{
    "a": BeEqual("a"),
    "b": BeEqual("b"),
})

func MatchAllFields

func MatchAllFields(fields Fields) types.GomegaMatcher

MatchAllFields succeeds if every field of a struct matches the field matcher associated with it, and every element matcher is matched.

Expect([]string{"a", "b"}).To(MatchAllFields(idFn, gstruct.Fields{
    "a": BeEqual("a"),
    "b": BeEqual("b"),
})

func MatchElements

func MatchElements(identifier Identifier, options Options, elements Elements) types.GomegaMatcher

MatchElements succeeds if each element of a slice matches the element matcher it maps to through the id function. It can ignore extra elements and/or missing elements.

Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing|IgnoreExtra, matchers.Elements{
    "a": BeEqual("a")
    "b": BeEqual("b"),
})

func MatchFields

func MatchFields(options Options, fields Fields) types.GomegaMatcher

MatchFields succeeds if each element of a struct matches the field matcher associated with it. It can ignore extra fields and/or missing fields.

Expect([]string{"a", "c"}).To(MatchFields(idFn, IgnoreMissing|IgnoreExtra, gstruct.Fields{
    "a": BeEqual("a")
    "b": BeEqual("b"),
})

func PointTo

func PointTo(matcher types.GomegaMatcher) types.GomegaMatcher

PointTo applies the given matcher to the value pointed to by actual. It fails if the pointer is nil.

actual := 5
Expect(&actual).To(PointTo(Equal(5)))

func Reject

func Reject() types.GomegaMatcher

Reject ignores the actual value and always fails. It can be used in conjunction with IgnoreMissing to catch problematic elements, or to verify tests are running.

Expect(nil).NotTo(Reject())
Expect(true).NotTo(Reject())

Types

type Elements

type Elements map[string]types.GomegaMatcher

Element ID to matcher.

type ElementsMatcher

type ElementsMatcher struct {
	// Matchers for each element.
	Elements Elements
	// Function mapping an element to the string key identifying its matcher.
	Identifier Identifier

	// Whether to ignore extra elements or consider it an error.
	IgnoreExtras bool
	// Whether to ignore missing elements or consider it an error.
	IgnoreMissing bool
	// Whether to key duplicates when matching IDs.
	AllowDuplicates bool
	// contains filtered or unexported fields
}

ElementsMatcher is a NestingMatcher that applies custom matchers to each element of a slice mapped by the Identifier function. TODO: Extend this to work with arrays & maps (map the key) as well.

func (*ElementsMatcher) FailureMessage

func (m *ElementsMatcher) FailureMessage(actual interface{}) (message string)

func (*ElementsMatcher) Failures

func (m *ElementsMatcher) Failures() []error

func (*ElementsMatcher) Match

func (m *ElementsMatcher) Match(actual interface{}) (success bool, err error)

func (*ElementsMatcher) NegatedFailureMessage

func (m *ElementsMatcher) NegatedFailureMessage(actual interface{}) (message string)

type Fields

type Fields map[string]types.GomegaMatcher

Field name to matcher.

type FieldsMatcher

type FieldsMatcher struct {
	// Matchers for each field.
	Fields Fields

	// Whether to ignore extra elements or consider it an error.
	IgnoreExtras bool
	// Whether to ignore missing elements or consider it an error.
	IgnoreMissing bool
	// contains filtered or unexported fields
}

func (*FieldsMatcher) FailureMessage

func (m *FieldsMatcher) FailureMessage(actual interface{}) (message string)

func (*FieldsMatcher) Failures

func (m *FieldsMatcher) Failures() []error

func (*FieldsMatcher) Match

func (m *FieldsMatcher) Match(actual interface{}) (success bool, err error)

func (*FieldsMatcher) NegatedFailureMessage

func (m *FieldsMatcher) NegatedFailureMessage(actual interface{}) (message string)

type Identifier

type Identifier func(element interface{}) string

Function for identifying (mapping) elements.

type IgnoreMatcher

type IgnoreMatcher struct {
	Succeed bool
}

A matcher that either always succeeds or always fails.

func (*IgnoreMatcher) FailureMessage

func (m *IgnoreMatcher) FailureMessage(_ interface{}) (message string)

func (*IgnoreMatcher) Match

func (m *IgnoreMatcher) Match(actual interface{}) (bool, error)

func (*IgnoreMatcher) NegatedFailureMessage

func (m *IgnoreMatcher) NegatedFailureMessage(_ interface{}) (message string)

type Options

type Options int

Options is the type for options passed to some matchers.

const (
	//IgnoreExtras tells the matcher to ignore extra elements or fields, rather than triggering a failure.
	IgnoreExtras Options = 1 << iota
	//IgnoreMissing tells the matcher to ignore missing elements or fields, rather than triggering a failure.
	IgnoreMissing
	//AllowDuplicates tells the matcher to permit multiple members of the slice to produce the same ID when
	//considered by the indentifier function. All members that map to a given key must still match successfully
	//with the matcher that is provided for that key.
	AllowDuplicates
)

type PointerMatcher

type PointerMatcher struct {
	Matcher types.GomegaMatcher
	// contains filtered or unexported fields
}

func (*PointerMatcher) FailureMessage

func (m *PointerMatcher) FailureMessage(_ interface{}) (message string)

func (*PointerMatcher) Match

func (m *PointerMatcher) Match(actual interface{}) (bool, error)

func (*PointerMatcher) NegatedFailureMessage

func (m *PointerMatcher) NegatedFailureMessage(actual interface{}) (message string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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