pact-foundation / pact-js-core

Core binaries for pact-js, a Contract Testing Framework. NOTE: If you are looking to do Pact contract testing in node, you almost certainly want pact-js, not pact-node.
https://docs.pact.io
MIT License
150 stars 79 forks source link

Multiple Provider Verifier type support #179

Closed ckotyan closed 2 years ago

ckotyan commented 5 years ago

Software versions

Expected behaviour

The message Pact should only verify contracts for message type consumers contracts and Http REST provider tests should only verify REST call like PACT type consumer contracts.

Actual behaviour

I have a micro service which has REST endpoints as well as it publishes messages when certain event happens. Hence I have 2 types of Providers in the PACT provider test suite: a MessagePact and a http REST pact; therefore there are 2 *Spec.js files. I am using the PACT broker to verify the providers. The issue I am seeing is when I run all the provider tests together, PACT fails the Message Pact tests while executing the REST provider pacts and vice versa.

My question is is this supported yet? if not is there a way to get around this issue? other than having different broker urls (1 for MessagePact and other for REST).

Steps to reproduce

This is the code snippet for running REST Pact provider verification: (providerPactSpec.js)

return new Verifier().verifyProvider({
            provider: serviceId,
            pactBrokerUrl: 'url',
            pactBrokerUsername: 'user',
            pactBrokerPassword: 'pwd',
            publishVerificationResult: false,
            providerVersion: `git short()`,
            timeout: 120000,
        });

And this is the code snippet for MessagePact provider verification (messagePactSpec.js).

            const messagePact = new MessageProviderPact({
                messageProviders: messageProviders,                
                provider: serviceId,
                pactBrokerUrl: 'url',
                pactBrokerUsername: 'user',
                pactBrokerPassword: 'pwd',
                publishVerificationResult: false,
                providerVersion: `git short()`,
                timeout: 120000,,
            });
            return await messagePact.verify();

Relevant log files

Will provide if needed

I am willing to contribute to help fix this if this is worth fixing.

mefellows commented 5 years ago

At the moment, you'll need to give your provider a different name (e.g. MyProvider and MyMessageProvider and publish the contracts that way. This will prevent that overlap.

My understanding is that you can't have both message and http interactions stored in a single contract file.

cc: @bethesque - any additional thoughts?

bethesque commented 5 years ago

We definitely want to support this use case. It's just a matter of finding the time. It will take a fair bit of work, because it's not just the publishing, it's also incorporating the results into can-i-deploy. I've raised an issue for it here but I'm not sure when it's going to get to the top of the priority list.

ckotyan commented 5 years ago

Hey @mefellows and @bethesque that was a very quick turnaround. Appreciate that. I will try different provider names and see if that resolves our issue.

BenCrinion-IW commented 3 years ago

Has there been any progress on this or do we still need separate providers for http and event contracts?

mefellows commented 3 years ago

Yes, the progress is that this will be a feature in the v4 specification (see https://github.com/pact-foundation/pact-specification/issues/79).

For clarity, it's currently not supported in Pact JS. Once the v3 version is live (which uses the new Rust core), when v4 closes, we can add that fairly quickly, along with plugins and other goodness.

mefellows commented 2 years ago

Closing as the specification now supports this (as above) and this package supports it. It needs to be exposed in Pact JS.