Reuben Tonna
03/04/2022, 2:45 PMfinal DslPart body = newJsonBody(root -> {
root.stringMatcher("callCount", "\\d+", "10");
root.unorderedMinArray("distribution", 0, item -> item.object(o -> {
o.stringMatcher("id", "\\d+", "1");
o.stringMatcher("callCount", "\\d+", "10");
}));
}).build();
return builder
.usingLegacyMessageDsl()
.given("non-empty-greeting-usage-statistics")
.expectsToReceive("private.metrics.greeting.usage")
.withContent(body)
.toPact(V4Pact.class);
My intent is to state that this consumer accepts message content of the general shape { callCount: x, distribution: [] } where distribution array can be empty, and if not empty the items must match the general structure { id: x, callCount: y }. The pact generates and is loaded in the broker. However when in my provider I return payloads such as:
"{\"callCount\":\"0\",\"distribution\":[]}";
It is failing with:
1) private.metrics.greeting.usage: generates a message which has a matching body
1.1) body: $.distribution Expected [{"callCount":"10","id":"1"}] to match [] ignoring order of elements
[
- {
- "callCount": "10",
- "id": "1"
- }
+
]
Any thoughts what I am missing? Maybe my expectation that in one pact I can define both scenarios were the array have items matching the example, or have no items is incorrect. Thoughts?Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)