pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

The array matcher: eachLike should require at least one example #546

Open ptornhult opened 7 years ago

ptornhult commented 7 years ago

If the eachLike matcher specifies Zero items the service provider implementing the Pact might only specify an empty array which would pass all tests. Once deployed, your provider could return an item that doesn't look like the one you expected, and then you have a bug (which you may or may not notice).

Right now the JVM version and JS version of eachLike behave differently in this regard. They should behave the same I would think/hope. It was a good catch by @bethesque to not allow this to slip into the JS version of Pact, but it should be fixed in the JVM version then. I can make a PR for this if you like?

Read the comments here for more info: https://github.com/pact-foundation/pact-js/pull/95

bethesque commented 7 years ago

Perhaps, in the interests of maintaining backwards compatibility for the jvm impl, we could print an obnoxious warning when a 0 length array is specified?

For the Rust impl, I'm pretty keen on not allowing 0 length.

uglyog commented 7 years ago

I prefer this to be an error, in the same way as giving an example value that does not match the regex causes an error.

bethesque commented 7 years ago

I'd prefer an error too, I just wasn't sure if you'd be cool with making it backwards incompatible.