pact-foundation / pact_broker

Enables your consumer driven contracts workflow
http://pactflow.io
MIT License
705 stars 173 forks source link

limitation in the pacticipant name? #98

Closed ndelacrz closed 7 years ago

ndelacrz commented 7 years ago

I was trying out the publishing of a pact contract to a pact broker.... But I noticed that when the name of my pacticipants have "-", example "test-consumer" / "test-provider", the pact contract could not be published. But when I changed the names to "test_consumer" and "test_provider", no issues at all. Is this a known limitation? Any other special characters I need to take note of?

bethesque commented 7 years ago

Not deliberately, seems like a bug. I'll look into it.

bethesque commented 7 years ago

Did you already have a test_consumer and/or test_provider in the pact broker before you tried to publish the pact with test-consumer/test-provider? Just check the response body for me - does it contain a message about publishing a potential duplicate?

ndelacrz commented 7 years ago

Yes, there is already a "test_provider" on the pact broker...

I removed them now (pact broker has no pact contract whatsoever now), and tried to publish again with "test-consumer1" and "test-provider1" (to make sure no other conflict with previous pact contracts), but still the same issue...

[INFO] --- pact-jvm-provider-maven_2.11:3.3.6:publish (pact-publish) @ test-consumer1 ---
Publishing test-consumer1-test-provider1.json ... FAILED! 409 Conflict - This is the first time a pact has been published for "test-consumer1".
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 36.996 s
[INFO] Finished at: 2017-05-11T08:57:25+02:00
[INFO] Final Memory: 69M/458M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven_2.11:3.3.6:publish (pact-publish) on project test-consumer1: One or more of the pact files were rejected by the pact broker -> [Help 1]
bethesque commented 7 years ago

@uglyog can we get the response body printed when there's an error?

bethesque commented 7 years ago

I'm 90% sure it's to do with an existing pacticipant with a slightly different name, unless publish is using a PATCH. There's logic in the broker to try and stop slightly different names being published to the broker (eg. one team publishes "foo_service" and another team publishes "foo-service", and then everyone wonders why they're not seeing all the pacts where they think they should be)

def is_conflict?
          merge_conflict = request.patch? && resource_exists? &&
            Pacts::Merger.conflict?(pact.json_content, pact_params.json_content)

          potential_duplicate_pacticipants?(pact_params.pacticipant_names) || merge_conflict
        end

Look under /pacticipants to make sure they're definitely all gone.

ndelacrz commented 7 years ago

aha! make that 100% @bethesque ! :)

Indeed there were still some pacticipants in the broker (I was checking the ui/relationships page when I said there are no more pact contracts...so lesson learned for me.. no pact contract != no pacticipants in the broker)

So I removed all pacticipants and published a pact with "-" in the pacticipant name... and success!!!


[INFO] --- pact-jvm-provider-maven_2.11:3.3.6:publish (pact-publish) @ test-consumer ---
Publishing test-consumer-test-provider.json ... HTTP/1.1 201 Created

thanks a lot for the support!

bethesque commented 7 years ago

No worries. Can you raise an issue in pact jvm provider maven thingy to print out the error message on failure? That would have told you what the issue was and how to fix it.

lovishpahwa commented 4 years ago

Same Exception and Solved

Error was almost same which is mentioned here https://github.com/pact-foundation/pact_broker/wiki/Troubleshooting#409-when-publishing-a-pact

Consumer/Provider with name "rockstar" was already published and second time when I published new contract with consumer/prover having name "Rockstar" (with first letter capital) then it was giving error and I discovered that pact-broker do not have any issue in adding '-' OR '_' but it take cares of case-sensitivity in names. When I corrected "Rockstar" with "rockstar" then it works and added new contract with same name.