Hi guys :slightly_smiling_face: I am implementing ...
# pact-jvm
r
Hi guys ๐Ÿ™‚ I am implementing a Provider verification tests class. This provider does not have any consumers yet, and I am receiving the
NoPactsFoundException: No Pact files were found to verify
exception. I have added the
@IgnoreNoPactsToVerify
annotation, and added a null check to the
PactVerificationContext
Here is the class:
Copy code
@Provider("${PACT_PROVIDER_NAME:}")
@PactBroker(url = "${PACT_BROKER_URL:}")
@IgnoreNoPactsToVerify
@RequiredArgsConstructor
@Slf4j
public class PactVerificationTests {
  
  @State("HAS_USERS")
  public void hasUsersState(Map<String, Object> params) throws URISyntaxException, IOException {
    ...

  }

  @BeforeEach
  void beforeEachInteraction(PactVerificationContext ctx) throws MalformedURLException {
    if(ctx == null){
      log.debug("Null PactVerificationContext received, no pacts to verify");
      return;
    }
    var interaction = ctx.getInteraction();
    var states = interaction.getProviderStates();
    if (states.size() > 1) {
      throw new AssertionError("Only 0 or 1 states are currently supported per interaction");
    }
    var targetUrl = Config.testedAppURL();
    ctx.setTarget(HttpTestTarget.fromUrl(new URL(targetUrl)));
  }

  @TestTemplate
  @ExtendWith(PactVerificationInvocationContextProvider.class)
  void pactVerificationTestTemplate(PactVerificationContext ctx) {
    if(ctx == null){
      log.debug("Null PactVerificationContext received, no pacts to verify");
      return;
    }
    ctx.verifyInteraction();
  }

}
The only selector I am using is
{"mainBranch": true}
, but as I said - this provider does not have any consumers yet. How could I overcome this exception? Thanks :)
b
What are you expecting to see when the provider has nothing to verify?
(e.g. Just no exception?)
r
@Boris Yes, for the exception to be caught, maybe logged, or even not thrown at all if possible, but ultimately for the verification to pass. I consider a provider with no consumers a valid state
b
Mmm yeah, you'll probably need a maintainer to answer that.
๐Ÿ‘ 1
r
I'm not really sure how, but the issue has been resolved. Thanks ๐Ÿ™‚
y
I consider a provider with no consumers a valid state
Pact doesnโ€™t
Therefore this would be a be a new feature request ๐Ÿ™‚
We have a public feature roadmap where users can search for existing and vote for their own https://pact.canny.io/
Does the provider even exist in your Pact Broker?
Copy code
> pact-broker can-i-deploy --pacticipant provider-foo --version foo


Pacticipant provider-foo not found
r
Sure does. As you replied in the thread below, can-i-deploy is not a good fit for a new service since it has no record deployed at all.
y
How do they exist in your pact broker?
Please donโ€™t invite me to huddles thank you
r
@Yousaf Nabi (pactflow.io) Sorry about that - clicked by mistake. They exist in my pact-broker since I defined a step in our service's pipeline that registers a service before any function/verification tests take place using the
create-or-update-pacticipant
call.
y
Ahh great, you have read the docs well then ๐Ÿ™‚ that is why you see the pacticipant as a first class item which returns a result, rather than the 404 on the pacticipant being found. Thanks for confirming and raising the feature req ๐Ÿ‘
๐Ÿ‘ 1
r
Thanks for the assistance.