Hello, about half a year ago I had a question on h...
# general
t
Hello, about half a year ago I had a question on how random data affects contract auto-validation: https://www.linen.dev/s/pact-foundation/t/18926283/hey-there-https-docs-pact-io-getting-started-matching-random . The info there was that random data generated by pact generators will be 'ignored' by Pact and the contract still auto-validated. For our project, I wrote a tool that creates the Pact matchers from the used DTOs. For some fields, I generate random example values myself and pass them in as the example value. However, it seems like this causes the broker to detect it as a new contract, eventhough (from what I can tell) only the "content" changed. But the content section is also changed when generators are used. On what criterion does the broker detect whether two contracts are equivalent?
m
It’s quite simple - the broker hashes the contents of the pact file. So if anything changes, it is considered a new contract. There are some good and some not-so-good reasons for this, but that’s the situation.
t
yeah, but the content also changes when using generators, doesn't it? @rholshausen said in the thread said that using generators would not prevent deduplication. From what I can tell I'm pretty sure that this is not the case when using
stringMatcher
without an example, which seems to generate new example values every run. I think this might be because pact-jvm doesn't set the seed on `Generex` . However @rholshausen also recommended me to set explicit example values on
stringMatcher
calls in other situations, so I'm just gonna try that and will come back to this if deduplication still doesn't work.
m
Yeah. If you use a generator and pass an example, then the contract doesn’t change (when the request is fired by the provider side verification, the value used might be different than what’s in the contract as it’s dynamically generated). Without an example, the consumer side always generates a new example value and therefore the contract changes
in an ideal world (I think), the broker would be aware of these semantics and ignore examples where a matcher/generator exists that has not changed