unmarshalledmatchers

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 8 Imported by: 1

README

Gomega matchers for more complicated json matching

This package provides Gomega matchers to match against either subsets of json/yaml, as well as json/yaml that has unordered lists. You can see an example of what that means below.

The functions of this library should follow the following pattern

(Match|Contain)(Ordered|Unordered)(JSON|YAML)( aStructureToUnmarshall, optional (With(Un)orderedListKeys(keys))

JsonMatchers()

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/benjamintf1/unmarshalledmatchers"
)

//Match with list ordering and optional json list keys exceptions
Expect(`{"a":[1,2,3],"b":[1,2,3],"c":[1,2,3]}`).Should(
	MatchUnorderedJSON(`{"a":[1,2,3],"b":[3,2,1],"c":[3,2,1]}`,
		WithOrderedListKeys("a"))) 
		
Expect(`{"a":[1,2,3],"b":[1,2,3],"c":[1,2,3]}`).Should(
	MatchOrderedJSON(`{"a":[3,2,1],"b":[1,2,3],"c":[1,2,3]}`,
		WithUnorderedListKeys("a")))

//Contain with list ordering and optional json list keys exceptions
Expect(`{"a":[1,2,3],"b":[1,2,3],"c":[1,2,3]}`).Should(
	ContainUnorderedJSON(`{"a":[1,2,3],"b":[3,2,1]}`,
		WithOrderedListKeys("a")))
		
Expect(`{"a":[1,2,3],"b":[1,2,3],"c":[1,2,3]}`).Should(
	ContainOrderedJSON(`{"a":[3,2,1],"b":[1,2,3]}`, 
		WithUnorderedListKeys("a")))


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainOrderedJSON

func ContainOrderedJSON(json interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for json with Ordered lists ie [1,2,3] is not equal to [2,3,1]. This is just like the default match json. This also is a subset match rather then a full match ie [1,2,3] contains [1,2] If you want to have some lists enforce order, add keys exclusions using Add WithUnorderedListKeys( json keys that refer to unordered lists )

func ContainOrderedYAML

func ContainOrderedYAML(YAML interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for yaml with Ordered lists ie [1,2,3] is not equal to [2,3,1]. This is just like the default match yaml. This also is a subset match rather then a full match ie [1,2,3] contains [1,2] If you want to have some lists enforce order, add keys exclusions using Add WithUnorderedListKeys( YAML keys that refer to unordered lists )

func ContainUnorderedJSON

func ContainUnorderedJSON(json interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for json with Unordered lists ie [1,2,3] is equal to [2,3,1]. This also is a subset match rather then a full match ie [1,2,3] contains [1,2] If you want to have some lists enforce order, add keys exclusions using Add WithOrderedListKeys( json keys that refer to unordered lists )

func ContainUnorderedYAML

func ContainUnorderedYAML(YAML interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for yaml with Unordered lists ie [1,2,3] is equal to [2,3,1]. This also is a subset match rather then a full match ie [1,2,3] contains [1,2] If you want to have some lists enforce order, add keys exclusions using Add WithOrderedListKeys( YAML keys that refer to unordered lists )

func MatchOrderedJSON

func MatchOrderedJSON(json interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for json with Ordered lists ie [1,2,3] is not equal to [2,3,1]. This is just like the default match json. If you want to have some lists enforce order, add keys exclusions using Add WithUnorderedListKeys( json keys that refer to unordered lists )

func MatchOrderedYAML

func MatchOrderedYAML(YAML interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for yaml with Ordered lists ie [1,2,3] is not equal to [2,3,1]. This is just like the default match yaml. If you want to have some lists enforce order, add keys exclusions using Add WithUnorderedListKeys( YAML keys that refer to unordered lists )

func MatchUnorderedJSON

func MatchUnorderedJSON(json interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for json with Unordered lists ie [1,2,3] is equal to [2,3,1]. If you want to have some lists enforce order, add keys exclusions using Add WithOrderedListKeys( json keys that refer to unordered lists )

func MatchUnorderedYAML

func MatchUnorderedYAML(YAML interface{}, keys ...KeyExclusions) types.GomegaMatcher

This is for yaml with Unordered lists ie [1,2,3] is equal to [2,3,1]. If you want to have some lists enforce order, add keys exclusions using Add WithOrderedListKeys( YAML keys that refer to unordered lists )

Types

type ExpandedJsonMatcher

type ExpandedJsonMatcher struct {
	JSONToMatch interface{}

	DeepMatcher UnmarshalledDeepMatcher
	// contains filtered or unexported fields
}

func (*ExpandedJsonMatcher) FailureMessage

func (matcher *ExpandedJsonMatcher) FailureMessage(actual interface{}) (message string)

func (*ExpandedJsonMatcher) Match

func (matcher *ExpandedJsonMatcher) Match(actual interface{}) (success bool, err error)

func (*ExpandedJsonMatcher) NegatedFailureMessage

func (matcher *ExpandedJsonMatcher) NegatedFailureMessage(actual interface{}) (message string)

type ExpandedYAMLMatcher

type ExpandedYAMLMatcher struct {
	YAMLToMatch interface{}

	DeepMatcher UnmarshalledDeepMatcher
	// contains filtered or unexported fields
}

func (*ExpandedYAMLMatcher) FailureMessage

func (matcher *ExpandedYAMLMatcher) FailureMessage(actual interface{}) (message string)

func (*ExpandedYAMLMatcher) Match

func (matcher *ExpandedYAMLMatcher) Match(actual interface{}) (success bool, err error)

func (*ExpandedYAMLMatcher) NegatedFailureMessage

func (matcher *ExpandedYAMLMatcher) NegatedFailureMessage(actual interface{}) (message string)

type KeyExclusions

type KeyExclusions interface {
	IsOrdered() bool
	GetMap() map[interface{}]bool
}

type OrderedKeys

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

func NewOrderedKeys

func NewOrderedKeys() OrderedKeys

func WithOrderedListKeys

func WithOrderedListKeys(keys ...interface{}) OrderedKeys

func (OrderedKeys) GetMap

func (k OrderedKeys) GetMap() map[interface{}]bool

func (OrderedKeys) IsOrdered

func (k OrderedKeys) IsOrdered() bool

type UnmarshalledDeepMatcher

type UnmarshalledDeepMatcher struct {
	Ordered            bool
	InvertOrderingKeys map[interface{}]bool
	Subset             bool
}

type UnorderedKeys

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

func NewUnorderedKeys

func NewUnorderedKeys() UnorderedKeys

func WithUnorderedListKeys

func WithUnorderedListKeys(keys ...interface{}) UnorderedKeys

func (UnorderedKeys) GetMap

func (k UnorderedKeys) GetMap() map[interface{}]bool

func (UnorderedKeys) IsOrdered

func (k UnorderedKeys) IsOrdered() bool

Jump to

Keyboard shortcuts

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