Documentation
¶
Index ¶
- Variables
- type HeadersMatcher
- type Map
- type MapMatcher
- type Matcher
- func ArrayContaining(variants []interface{}) Matcher
- func ArrayMaxLike(content interface{}, max int) Matcher
- func ArrayMinMaxLike(content interface{}, min int, max int) Matcher
- func Date() Matcher
- func DateGenerated(example string, format string) Matcher
- func DateTimeGenerated(example string, format string) Matcher
- func Decimal(example float64) Matcher
- func EachKeyLike(key string, template interface{}) Matcher
- func EachLike(content interface{}, minRequired int) Matcher
- func Equality(content interface{}) Matcher
- func FromProviderState(expression, example string) Matcher
- func HexValue() Matcher
- func IPAddress() Matcher
- func IPv6Address() Matcher
- func Identifier() Matcher
- func Includes(content string) Matcher
- func Integer(example int) Matcher
- func Like(content interface{}) Matcher
- func MatchV2(src interface{}) Matcher
- func Term(generate string, matcher string) Matcher
- func Time() Matcher
- func TimeGenerated(example string, format string) Matcher
- func Timestamp() Matcher
- func UUID() Matcher
- type MetadataMatcher
- type Null
- type QueryMatcher
- type S
- type String
- type StructMatcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ArrayMinLike = EachLike
var IPv4Address = IPAddress
IPv4Address matches valid IPv4 addresses.
var Regex = Term
Regex is a more appropriately named alias for the "Term" matcher
Functions ¶
This section is empty.
Types ¶
type HeadersMatcher ¶
type Map ¶
type Map MapMatcher
type MapMatcher ¶
MapMatcher allows a map[string]string-like object to also contain complex matchers
func (*MapMatcher) UnmarshalJSON ¶
func (m *MapMatcher) UnmarshalJSON(bytes []byte) (err error)
UnmarshalJSON is a custom JSON parser for MapMatcher It treats the matchers as strings
type Matcher ¶
type Matcher interface { // GetValue returns the raw generated value for the matcher // without any of the matching detail context GetValue() interface{} // contains filtered or unexported methods }
Matcher allows various implementations such String or StructMatcher to be provided in when matching with the DSL We use the strategy outlined at http://www.jerf.org/iri/post/2917 to create a "sum" or "union" type.
func ArrayContaining ¶
func ArrayContaining(variants []interface{}) Matcher
ArrayContaining allows heterogenous items to be matched within a list. Unlike EachLike which must be an array with elements of the same shape, ArrayContaining allows objects of different types and shapes.
func ArrayMaxLike ¶
ArrayMaxLike is like EachLike except has a bounds on the max https://github.com/pact-foundation/pact-specification/tree/version-3#add-a-minmax-type-matcher
func ArrayMinMaxLike ¶
ArrayMinMaxLike is like EachLike except has a bounds on the max and the min https://github.com/pact-foundation/pact-specification/tree/version-3#add-a-minmax-type-matcher
func Date ¶
func Date() Matcher
Date matches a pattern corresponding to the ISO_DATE_FORMAT, which is "yyyy-MM-dd". The current date is used as the eaxmple.
func DateGenerated ¶
DateGenerated matches a cross platform formatted date, and generates a current date during verification String example value must match the provided date format string. See Java SimpleDateFormat https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for formatting options
func DateTimeGenerated ¶
DateTimeGenerated matches a cross platform formatted datetime, and generates a current datetime during verification String example value must match the provided datetime format string. See Java SimpleDateFormat https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for formatting options
func EachKeyLike ¶
Object where the key itself is ignored, but the value template must match.
key - Example key to use (which will be ignored) template - Example value template to base the comparison on
func EachLike ¶
EachLike specifies that a given element in a JSON body can be repeated "minRequired" times. Number needs to be 1 or greater
Example ¶
match := EachLike(1, 3) fmt.Println(formatJSON(match))
Output: { "pact:matcher:type": "type", "value": [ 1, 1, 1 ], "min": 3 }
func Equality ¶
func Equality(content interface{}) Matcher
Equality resets matching cascades back to equality see https://github.com/pact-foundation/pact-specification/tree/version-3#add-an-equality-matcher
func FromProviderState ¶
Marks a item as to be injected from the provider state
"expression" is used to lookup the dynamic value from the provider state context during verification "example" is the example value to used in the consumer test
func IPAddress ¶
func IPAddress() Matcher
IPAddress defines a matcher that accepts valid IPv4 addresses.
func IPv6Address ¶
func IPv6Address() Matcher
IPv6Address defines a matcher that accepts IP addresses.
func Identifier ¶
func Identifier() Matcher
Identifier defines a matcher that accepts integer values.
func Like ¶
func Like(content interface{}) Matcher
Like specifies that the given content type should be matched based on type (int, string etc.) instead of a verbatim match.
Example (Number) ¶
match := Like(42) fmt.Println(formatJSON(match))
Output: { "specification": "2.0.0", "pact:matcher:type": "type", "value": 42 }
Example (Object) ¶
match := Like(map[string]string{"baz": "bat"}) fmt.Println(formatJSON(match))
Output: { "specification": "2.0.0", "pact:matcher:type": "type", "value": { "baz": "bat" } }
Example (String) ¶
match := Like("myspecialvalue") fmt.Println(formatJSON(match))
Output: { "specification": "2.0.0", "pact:matcher:type": "type", "value": "myspecialvalue" }
func MatchV2 ¶
func MatchV2(src interface{}) Matcher
Match recursively traverses the provided type and outputs a matcher string for it that is compatible with the Pact dsl. By default, it requires slices to have a minimum of 1 element. For concrete types, it uses `dsl.Like` to assert that types match. Optionally, you may override these defaults by supplying custom pact tags on your structs.
Supported Tag Formats Minimum Slice Size: `pact:"min=2"` String RegEx: `pact:"example=2000-01-01,regex=^\\d{4}-\\d{2}-\\d{2}$"`
func Term ¶
Term specifies that the matching should generate a value and also match using a regular expression.
Example ¶
match := Term("myawesomeword", `\w+`) fmt.Println(formatJSON(match))
Output: { "pact:matcher:type": "regex", "value": "myawesomeword", "regex": "\\w+" }
func Time ¶
func Time() Matcher
Time matches a pattern corresponding to the ISO_DATE_FORMAT, which is "'T'HH:mm:ss". The current tem is used as the eaxmple.
func TimeGenerated ¶
TimeGenerated matches a cross platform formatted date, and generates a current time during verification String example value must match the provided time format string. See Java SimpleDateFormat https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for formatting options
type MetadataMatcher ¶
type MetadataMatcher = MapMatcher
type QueryMatcher ¶
QueryMatcher matches a query string interface type QueryMatcher map[string][]interface{} // Why was it an interface and not the same as the others? Can only be string values anyway, or
type S ¶
type S string
S is the string primitive wrapper (alias) for the Matcher type, it allows plain strings to be matched To keep backwards compatible with previous versions we aren't using an alias here
func (S) GetValue ¶
func (s S) GetValue() interface{}
GetValue returns the raw generated value for the matcher without any of the matching detail context
func (S) MarshalJSON ¶
type String ¶
type String string
String is the longer named form of the string primitive wrapper, it allows plain strings to be matched
func (String) GetValue ¶
func (s String) GetValue() interface{}
GetValue returns the raw generated value for the matcher without any of the matching detail context
func (String) MarshalJSON ¶
type StructMatcher ¶
type StructMatcher map[string]interface{}
StructMatcher matches a complex object structure, which may itself contain nested Matchers
func (StructMatcher) GetValue ¶
func (m StructMatcher) GetValue() interface{}
GetValue returns the raw generated value for the matcher without any of the matching detail context