-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
527 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
{ | ||
"consumer": { | ||
"name": "consumer" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "A request to do a foo", | ||
"providerStates": [ | ||
{ | ||
"name": "User foo exists", | ||
"params": { | ||
"id": "foo" | ||
} | ||
} | ||
], | ||
"request": { | ||
"body": { | ||
"name": "billy" | ||
}, | ||
"headers": { | ||
"Authorization": "Bearer 1234", | ||
"Content-Type": "application/json" | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.name": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
} | ||
}, | ||
"headers": { | ||
"$.Authorization": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"$.Content-Type": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
} | ||
}, | ||
"path": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "\\/foo.*" | ||
} | ||
] | ||
}, | ||
"query": { | ||
"$.baz[0]": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "[a-z]+" | ||
} | ||
] | ||
}, | ||
"$.baz[1]": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "[a-z]+" | ||
} | ||
] | ||
}, | ||
"$.baz[2]": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "[a-z]+" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"method": "POST", | ||
"path": "/foobar", | ||
"query": { | ||
"baz": [ | ||
"bar", | ||
"bat", | ||
"baz" | ||
] | ||
} | ||
}, | ||
"response": { | ||
"body": { | ||
"accountBalance": 123.76, | ||
"dateTime": "2020-01-01", | ||
"equality": "a thing", | ||
"id": 12, | ||
"itemsMin": [ | ||
"min", | ||
"min", | ||
"min" | ||
], | ||
"itemsMinMax": [ | ||
27, | ||
27, | ||
27, | ||
27, | ||
27 | ||
], | ||
"lastName": "LastName", | ||
"name": "FirstName", | ||
"superstring": "foo" | ||
}, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"matchingRules": { | ||
"body": { | ||
"$.accountBalance": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "decimal" | ||
} | ||
] | ||
}, | ||
"$.dateTime": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "regex", | ||
"regex": "[0-9\\-]+" | ||
} | ||
] | ||
}, | ||
"$.equality": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "equality" | ||
} | ||
] | ||
}, | ||
"$.id": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "integer" | ||
} | ||
] | ||
}, | ||
"$.itemsMin": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"$.itemsMinMax": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type", | ||
"max": 5 | ||
} | ||
] | ||
}, | ||
"$.lastName": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"$.name": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
}, | ||
"$.superstring": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "include", | ||
"value": "foo" | ||
} | ||
] | ||
} | ||
}, | ||
"headers": { | ||
"$.Content-Type": { | ||
"combine": "AND", | ||
"matchers": [ | ||
{ | ||
"match": "type" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"status": 200 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pactGo": { | ||
"version": "v1.4.3" | ||
}, | ||
"pactRust": { | ||
"version": "0.6.3" | ||
}, | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "provider" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package v3 | ||
|
||
import "time" | ||
|
||
// Term Matcher regexes | ||
const ( | ||
hexadecimal = `[0-9a-fA-F]+` | ||
ipAddress = `(\d{1,3}\.)+\d{1,3}` | ||
ipv6Address = `(\A([0-9a-f]{1,4}:){1,1}(:[0-9a-f]{1,4}){1,6}\Z)|(\A([0-9a-f]{1,4}:){1,2}(:[0-9a-f]{1,4}){1,5}\Z)|(\A([0-9a-f]{1,4}:){1,3}(:[0-9a-f]{1,4}){1,4}\Z)|(\A([0-9a-f]{1,4}:){1,4}(:[0-9a-f]{1,4}){1,3}\Z)|(\A([0-9a-f]{1,4}:){1,5}(:[0-9a-f]{1,4}){1,2}\Z)|(\A([0-9a-f]{1,4}:){1,6}(:[0-9a-f]{1,4}){1,1}\Z)|(\A(([0-9a-f]{1,4}:){1,7}|:):\Z)|(\A:(:[0-9a-f]{1,4}){1,7}\Z)|(\A((([0-9a-f]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[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0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$` | ||
date = `^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))?)` | ||
timeRegex = `^(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?$` | ||
) | ||
|
||
var timeExample = time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC) | ||
|
||
// MatcherClass is used to differentiate the various matchers when serialising | ||
type MatcherClass string | ||
|
||
// Matcher Types used to discriminate when serialising the rules | ||
const ( | ||
// likeMatcher is the ID for the Like Matcher | ||
likeMatcher MatcherClass = "likeMatcher" | ||
|
||
// regexMatcher is the ID for the Term Matcher | ||
regexMatcher = "regexMatcher" | ||
|
||
// arrayMinLikeMatcher is the ID for the ArrayMinLike Matcher | ||
arrayMinLikeMatcher = "arrayMinLikeMatcher" | ||
|
||
// arrayMaxLikeMatcher is the ID for the arrayMaxLikeMatcher Matcher | ||
// arrayMaxLikeMatcher = "arrayMaxLikeMatcher" | ||
|
||
// arrayMinMaxLikeMatcher sets lower and upper bounds on the array size | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-a-minmax-type-matcher | ||
arrayMinMaxLikeMatcher = "arrayMinMaxLikeMatcher" | ||
|
||
// Matches map[string]interface{} types is basically a container for other matchers | ||
structTypeMatcher = "structTypeMatcher" | ||
|
||
// Matches integers | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-more-specific-type-matchers | ||
integerMatcher = "intMatcher" | ||
|
||
// Matches decimals | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-more-specific-type-matchers | ||
decimalMatcher = "decimalMatcher" | ||
|
||
// Matches nulls | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-more-specific-type-matchers | ||
nullMatcher = "nullMatcher" | ||
|
||
// Equality matcher | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-an-equality-matcher | ||
equalityMatcher = "equalityMatcher" | ||
|
||
// includes matcher | ||
// https://github.com/pact-foundation/pact-specification/tree/version-3#add-an-include-matcher | ||
includesMatcher = "includesMatcher" | ||
) |
Oops, something went wrong.