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

Pact JSON file is not overwritten when a RequestResponsePact is removed from Test #471

Open shyamz-22 opened 7 years ago

shyamz-22 commented 7 years ago

Hello There,

We are using pact-jvm-consumer-junit_2.11 v3.4.1

We observed that when we remove a pact(RequestResponsePact) from an existing pact test, the changes are not reflected in the generated pact JSON file. Looks like the pact JSON is just merging the newly added/updated changes however it is not deleting the removed pact test(RequestResponsePact)

This was the behaviour with v3.3.6 and I am not sure if this is feature or bug as this behaviour is changed with v3.4.x+. If this is a feature I would like to have a configuration flag that always sets the file generation to overwrite mode as in https://github.com/realestate-com-au/pact/blob/master/documentation/configuration.md#pactfile_write_mode

uglyog commented 7 years ago

This has been done this way due to people splitting their pact tests over multiple test classes. The problem with JVM build tools is they may run tests concurrently with multiple threads and/or JVM processes. It just simplifies things by merging the results at the file level.

If you are removing tests and your pacts are being generated into the build directory, a clean before the test run will result in the correct pacts being generated.

Having an option to control merging is a good idea, but if the files are being overwritten then you could never have more than one test for the same consumer + provider pair.