Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No pacts found for provider #1284

Closed
upanshu21 opened this issue Jan 8, 2021 · 3 comments
Closed

No pacts found for provider #1284

upanshu21 opened this issue Jan 8, 2021 · 3 comments

Comments

@upanshu21
Copy link

upanshu21 commented Jan 8, 2021

I am writing consumer-driven contract test cases for an event-based service and using a pact broker. My consumer is able to generate the pact successfully

@Tag(TestTags.MEDIUM_TESTS)
public class MessageConsumerTest {

  @ParameterizedTest
  @ConsumerMessageSource(finder = MessageFinder.class)
  void generateMessagePact(ConsumerMessage consumerMessage) {
    Assertions.assertDoesNotThrow(() -> ConsumerMessagePactGenerator.generateAndWritePact(consumerMessage));
  }

output:

Generating Pact: 

{"body":{"InitialId":"string","message":{"messageBody":"string"}}

I wrote the provider test for the same service:


@Tag(TestTags.CONTRACT_TESTS)
@PactSource(PactBrokerSourceLoader.class)
public class MessageProviderTest {

  private final MessageIndex messageIndex = new MessageIndex();

  @ParameterizedTest
  @ConsumerMessagePactSource(provider = MessageFinder.APP_NAME, config = CmdPactBrokerConfig.class)
  void messageShouldSatisfyPact(ConsumerMessagePact consumerMessagePact) throws JsonProcessingException {
    String actualMessage = messageIndex.getMessageInstanceAsString(consumerMessagePact.getMessageName());
    System.out.println("hello"+actualMessage);
    MessagePactVerifier.verifyProviderMessageMatchesPact(consumerMessagePact.getMessage(), actualMessage);
  }

Pact broker configurations are given in the CmdPactBrokerConfig.class

The test cases do not run and give the output:

15:21:38.037 [main] WARN com.demo.contract.message.provider.helpers.loaders.PactBrokerSourceLoader - No pacts found for provider 'demo-service' with versions 'latest, develop'
15:21:40.049 [main] WARN com.demo.contract.message.provider.helpers.arguments.ConsumerMessagePactArgumentsProvider - Unable parse pact: au.com.dius.pact.model.RequestResponsePact cannot be cast to au.com.dius.pact.model.v3.messaging.MessagePact

New to contract tests so need guidance on this. Any idea what could be wrong? Any example I can refer to for writing contract tests for event-based service.

@mefellows
Copy link
Member

mefellows commented Jan 8, 2021

Looks like at least two issues:

  1. The version 'latest, develop' looks like it's not being passed as an array, but a string with commas in it. It may be an artifact of the way the logging happens, but worth double checking (because I assume you are trying to find pacts tagged latest and develop)
  2. Don't use latest as a tag (see the tagging documentation at docs.pact.io)
  3. This error Unable parse pact: au.com.dius.pact.model.RequestResponsePact cannot be cast to au.com.dius.pact.model.v3.messaging.MessagePact suggests that the pact that was found, was not a message pact but contained the standard HTTP / REST based pacts. See Combine message and rest interactions in the same file pact-specification#79 for more on this. The current workaround is to have a different provider name for messages and http ones

@uglyog
Copy link
Member

uglyog commented Jan 10, 2021

As @mefellows mentioned, 'latest, develop' are tags, not versions. Whatever is implementing @ConsumerMessagePactSource needs to set the correct fields.

In your consumer test, ConsumerMessagePactGenerator.generateAndWritePact is generating the wrong type of Pact file.

These are not Pact-JVM classes, could you raise this issue with the project that provides those?

@upanshu21
Copy link
Author

Yup. Actually the provider had a wrapper on top of the pact-jvm. thanks for the help closing this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants