Support matching multiple occurrences of a query parameter exactly
Software versions
- OS: linux
- Consumer Pact library: Pact go v1.5.3
- Provider Pact library: Pact go v1.5.3
- Golang Version: 1.15
Expected behaviour
The pact go library should allow to exactly match multiple occurrences of the same query parameter as it is supported within pact files and by libraries for other platforms as shown e.g. here.
Actual behaviour
The Pact go library doesn't support matching multiple values of the same query parameter precisely.
Steps to reproduce
pact.
AddInteraction().
Given("Some state").
UponReceiving("A request with multiple occurrences of a query parameter").
WithRequest(dsl.Request{
Method: "GET",
Path: dsl.String("/api/v1/resource"),
Query: dsl.MapMatcher{
"myparam": dsl.Like([]string{"value1", "value2"}),
},
}).
...
Unfortunately this doesn't work because the query parameter values are treated as a nested slice resulting in this diff within the consumer test log:
{
"query": {
"myparam": [
- [
- "value1",
- "value2",
- ],
+ "value1",
+ "value2",
]
}
}
Actually I'd like to specify the parameters like this:
...
Query: dsl.MapMatcher{
"myparam": []string{"value1", "value2"},
},
...
However the Pact Go DSL doesn't allow me to do so since it requires me to provide a Matcher for the value but there is no matcher to precisely match an array. Supporting such a matcher could be a solution to this problem.
Workaround
A workaround is to match the query parameter values in a less precise way using dsl.EachLike:
...
Query: dsl.MapMatcher{
"myparam": dsl.EachLike(dsl.Term("value1", "value1|value2"), 2),
},
...