It might be a dumb question, but are there any goo...
# protobufs
s
It might be a dumb question, but are there any good examples on how to specify matching rules for values in a map? I'm struggling to understand the syntax tbh, like where do you put the matching rules. Like how can we say the map accepts 0+ fields and both key and value are strings (basically
map<string, string> labels = 4
in the .proto file). I've tried:
Copy code
"labels": {"pact:match": "eachKey(matching(type, 'some-key')), eachValue(matching(type, 'some-value'))"}
and got
rpc error: code = FailedPrecondition desc = Failed to match the request message - BodyMismatches({"$.destination": [BodyMismatch { path: "$.destination.labels", expected: None, actual: None, mismatch: "Expected repeated field 'labels' to be empty but received 1 values" }]})
Copy code
"labels": {"pact:match": "atLeast(0), eachKey(matching(type, 'some-key')), eachValue(matching(type, 'some-value'))"},
and it gave me an error
2024-01-31 22:44:50.5126  ┃ 2024-02-01T06:44:50.498712Z ERROR ThreadId(01) pact_ffi::plugins: Failed to call out to plugin - min-type is not a valid matching rule type
(or at least that's the error I found in the debug logs, in info it was the usual 'pact file contains no protobuf descriptors')
also, conceptually, is it better to do multiple pacts, one with 0 values, one with 1 value, one with multiple values?
r
Yes, a sperate test for each different combination you want to assert. But I would normally just do 2: empty and not empty
I'll see if I can replicate the issue you are seeing
s
Thanks! Yeah, I've seen those docs, they're good but miss important point - how to apply those matchers for list and map fields, e.g. where do you put
eachKey
and
eachValue
? I was kinda semi-guessing based on your previous comments 🙂
r
Just coming back to this
how can we say the map accepts 0+ fields
This is the default behavior with the
eachKey
and
eachValue
functions, you don't need anything else
Think I have replicated the problem, will try create a fix
thankyou 2 1
s
ooh, seems like the first issue here is the same as the one for which I've opened a separate ticket 😅 https://pact-foundation.slack.com/archives/CEQBDD5U4/p1707272916302469
r
0.3.12 released with some fixes
thankyou 2 1
🎉 1