...

Package gstruct

import "github.com/onsi/gomega/gstruct"
Overview
Index
Subdirectories

Overview ▾

Index ▾

func Ignore() types.GomegaMatcher
func IndexIdentity(index int, _ interface{}) string
func MatchAllElements(identifier Identifier, elements Elements) types.GomegaMatcher
func MatchAllElementsWithIndex(identifier IdentifierWithIndex, elements Elements) types.GomegaMatcher
func MatchAllFields(fields Fields) types.GomegaMatcher
func MatchAllKeys(keys Keys) types.GomegaMatcher
func MatchElements(identifier Identifier, options Options, elements Elements) types.GomegaMatcher
func MatchElementsWithIndex(identifier IdentifierWithIndex, options Options, elements Elements) types.GomegaMatcher
func MatchFields(options Options, fields Fields) types.GomegaMatcher
func MatchKeys(options Options, keys Keys) types.GomegaMatcher
func PointTo(matcher types.GomegaMatcher) types.GomegaMatcher
func Reject() types.GomegaMatcher
type Elements
type ElementsMatcher
    func (m *ElementsMatcher) FailureMessage(actual interface{}) (message string)
    func (m *ElementsMatcher) Failures() []error
    func (m *ElementsMatcher) Match(actual interface{}) (success bool, err error)
    func (m *ElementsMatcher) NegatedFailureMessage(actual interface{}) (message string)
type Fields
type FieldsMatcher
    func (m *FieldsMatcher) FailureMessage(actual interface{}) (message string)
    func (m *FieldsMatcher) Failures() []error
    func (m *FieldsMatcher) Match(actual interface{}) (success bool, err error)
    func (m *FieldsMatcher) NegatedFailureMessage(actual interface{}) (message string)
type Identifier
    func (i Identifier) WithIndexAndElement(index int, element interface{}) string
type IdentifierWithIndex
    func (i IdentifierWithIndex) WithIndexAndElement(index int, element interface{}) string
type Identify
type IgnoreMatcher
    func (m *IgnoreMatcher) FailureMessage(_ interface{}) (message string)
    func (m *IgnoreMatcher) Match(actual interface{}) (bool, error)
    func (m *IgnoreMatcher) NegatedFailureMessage(_ interface{}) (message string)
type Keys
type KeysMatcher
    func (m *KeysMatcher) FailureMessage(actual interface{}) (message string)
    func (m *KeysMatcher) Failures() []error
    func (m *KeysMatcher) Match(actual interface{}) (success bool, err error)
    func (m *KeysMatcher) NegatedFailureMessage(actual interface{}) (message string)
type Options
type PointerMatcher
    func (m *PointerMatcher) FailureMessage(_ interface{}) (message string)
    func (m *PointerMatcher) Match(actual interface{}) (bool, error)
    func (m *PointerMatcher) NegatedFailureMessage(actual interface{}) (message string)

Package files

elements.go fields.go ignore.go keys.go pointer.go types.go

func Ignore

func Ignore() types.GomegaMatcher

Ignore ignores the actual value and always succeeds.

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

func IndexIdentity

func IndexIdentity(index int, _ interface{}) string

IndexIdentity is a helper function for using an index as the key in the element map

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.

idFn := func(element interface{}) string {
    return fmt.Sprintf("%v", element)
}

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

func MatchAllElementsWithIndex

func MatchAllElementsWithIndex(identifier IdentifierWithIndex, elements Elements) types.GomegaMatcher

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

idFn := func(index int, element interface{}) string {
    return strconv.Itoa(index)
}

Expect([]string{"a", "b"}).To(MatchAllElements(idFn, Elements{
    "0": Equal("a"),
    "1": Equal("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.

actual := struct{
  A int
  B []bool
  C string
}{
  A: 5,
  B: []bool{true, false},
  C: "foo",
}

Expect(actual).To(MatchAllFields(Fields{
  "A": Equal(5),
  "B": ConsistOf(true, false),
  "C": Equal("foo"),
}))

func MatchAllKeys

func MatchAllKeys(keys Keys) types.GomegaMatcher

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.

idFn := func(element interface{}) string {
    return fmt.Sprintf("%v", element)
}

Expect([]string{"a", "b", "c"}).To(MatchElements(idFn, IgnoreExtras, Elements{
    "a": Equal("a"),
    "b": Equal("b"),
}))
Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing, Elements{
    "a": Equal("a"),
    "b": Equal("b"),
    "c": Equal("c"),
    "d": Equal("d"),
}))

func MatchElementsWithIndex

func MatchElementsWithIndex(identifier IdentifierWithIndex, options Options, elements Elements) types.GomegaMatcher

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

idFn := func(index int, element interface{}) string {
    return strconv.Itoa(index)
}

Expect([]string{"a", "b", "c"}).To(MatchElements(idFn, IgnoreExtras, Elements{
    "0": Equal("a"),
    "1": Equal("b"),
}))
Expect([]string{"a", "c"}).To(MatchElements(idFn, IgnoreMissing, Elements{
    "0": Equal("a"),
    "1": Equal("b"),
    "2": Equal("c"),
    "3": Equal("d"),
}))

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.

actual := struct{
  A int
  B []bool
  C string
}{
  A: 5,
  B: []bool{true, false},
  C: "foo",
}

Expect(actual).To(MatchFields(IgnoreExtras, Fields{
  "A": Equal(5),
  "B": ConsistOf(true, false),
}))
Expect(actual).To(MatchFields(IgnoreMissing, Fields{
  "A": Equal(5),
  "B": ConsistOf(true, false),
  "C": Equal("foo"),
  "D": Equal("extra"),
}))

func MatchKeys

func MatchKeys(options Options, keys Keys) types.GomegaMatcher

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())

type Elements

Element ID to matcher.

type Elements map[string]types.GomegaMatcher

type ElementsMatcher

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.

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

    // 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
}

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

Field name to matcher.

type Fields map[string]types.GomegaMatcher

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

Function for identifying (mapping) elements.

type Identifier func(element interface{}) string

func (Identifier) WithIndexAndElement

func (i Identifier) WithIndexAndElement(index int, element interface{}) string

Calls the underlying fucntion with the provided params. Identifier drops the index.

type IdentifierWithIndex

Uses the index and element to generate an element name

type IdentifierWithIndex func(index int, element interface{}) string

func (IdentifierWithIndex) WithIndexAndElement

func (i IdentifierWithIndex) WithIndexAndElement(index int, element interface{}) string

Calls the underlying fucntion with the provided params. IdentifierWithIndex uses the index.

type Identify

Interface for identifing the element

type Identify interface {
    WithIndexAndElement(i int, element interface{}) string
}

type IgnoreMatcher

A matcher that either always succeeds or always fails.

type IgnoreMatcher struct {
    Succeed bool
}

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 Keys

type Keys map[interface{}]types.GomegaMatcher

type KeysMatcher

type KeysMatcher struct {
    // Matchers for each key.
    Keys Keys

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

func (*KeysMatcher) FailureMessage

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

func (*KeysMatcher) Failures

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

func (*KeysMatcher) Match

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

func (*KeysMatcher) NegatedFailureMessage

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

type Options

Options is the type for options passed to some matchers.

type Options int
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)

Subdirectories

Name Synopsis
..
errors