Rinka Yoshida
04/16/2024, 12:00 AMGetString()
method to Matcher type, so that instead of doing this:
grpcInteraction := struct {
PactProtoService string `json:"pact:proto-service"`
Request any `json:"request"`
Response any `json:"response,omitempty"`
}{
PactProtoService: "MyService",
Request: map[string]interface{}{
"user_id": "matching(integer, 100)",
},
Response: map[string]interface{}{
"first_name": "matching(type, 'random')",
"last_name": "matching(type, 'random')",
},
}
We can do below instead:
grpcInteraction := struct {
PactProtoService string `json:"pact:proto-service"`
Request string `json:"request"`
Response string `json:"response,omitempty"`
}{
PactProtoService: "MyService",
Request: StructMatcher{
"user_id": Integer(100),
}.ToString(),
Response: StructMatcher{
"first_name": Like("random"),
"last_name": Like("random"),
}.ToString(),
}
For example matchers.Integer(100).ToString()
would be {"specification":"3.0.0","pact:matcher:type":"integer","value":100}
.
I tried it on like which Integer users. However, I'm running into the issue of
Request to configure interaction failed: Failed to process protobuf: Field values must be configured with a string value, got Object {"pact:matcher:type": String("integer"), "specification": String("3.0.0"), "value": Number(100.0)}
I learnt that matching evaluation is not done recursively https://pact-foundation.slack.com/archives/C9UTHTFFB/p1712026514061369?thread_ts=1711759161.767629&cid=C9UTHTFFB, so I was wondering if you know there's another way we can get the string representation of match expressions? Or is there a way to bypass the recursion issue?Matt (pactflow.io / pact-js / pact-go)
rholshausen
04/17/2024, 4:13 AMrholshausen
04/17/2024, 4:18 AMeachValue(matching(type, 'random'))
resolves to (EachValueMatcher((TypeMatcher, "random", None)), None, None)
Matt (pactflow.io / pact-js / pact-go)
pactffi_with_body
, pactffi_with_header_v2
etc.), can you use either an expression or a matching rule?
Does this also mean plugins can use either, or is that entirely up to the plugin author?
I’m a little confused on the interfaces/boundaries, and where things can be usedrholshausen
04/17/2024, 6:28 AMSo as a follow up, when using the FFI methods (Yes,pactffi_with_body
etc.), can you use either an expression or a matching rule?pactffi_with_header_v2
rholshausen
04/17/2024, 6:29 AMDoes this also mean plugins can use either, or is that entirely up to the plugin author?No, plugin configuration only supports basic values and expressions
rholshausen
04/17/2024, 6:29 AMI’m a little confused on the interfaces/boundaries, and where things can be usedYes
rholshausen
04/17/2024, 6:30 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Rinka Yoshida
04/18/2024, 12:20 AMcreate a similar thing though, that knows how to take a struct and serialise expressions.Was trying to avoid this but good to see this is the way to go. That makes sense, thank you both for chiming in so fast!
Matt (pactflow.io / pact-js / pact-go)