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

Internal verification of the contract is not generating requests #135

Open
IgorCandido opened this issue Apr 11, 2019 · 0 comments
Open

Comments

@IgorCandido
Copy link

IgorCandido commented Apr 11, 2019

Hi,

I've been trying to check the contract on the provider and I am facing a very puzzling result.

So to provide context I have a pact file that looks like:

  "provider" : {
    "name" : "Provider"
  },
  "consumer" : {
    "name" : "Client"
  },
  "interactions" : [
    {
      "description" : "Transaction- Successful",
      "request" : {
        "method" : "POST",
        "path" : "/api/v1/transaction.do",
        "matchingRules" : {
          "$.body.amount" : {
            "match" : "regex",
            "regex" : "^[a-zA-Z0-9]{,20}$"
          }
        }
      },
      "response" : {
        "status" : 200,
        "body" : {
          "transactionId" : "1110000000000328568"
        },
        "matchingRules" : {
          "$.body.transactionId" : {
            "match" : "regex",
            "regex" : "^[a-zA-Z0-9]{,20}$"
          }
        }
      }
    }
  ]
}

On the provider, I then execute the following code within a test:

verifyPact
          .withPactSource(pactAsJsonString(consumerProviderJson))
          .runStrictVerificationAgainst("localhost", port)

I am using the following code to generate the said pact file:

forgeStrictPact
        .between("Client")
        .and("Provider")
        .addInteraction(
          interaction
            .description("Transaction- Successful")
            .uponReceiving(
              method = POST,
              path = "/api/v1/transaction.do",
              query = None,
              headers = Map.empty,
              body = None,
              matchingRules = bodyRegexRule("amount", "^[a-zA-Z0-9]{,20}$")
            )
            .willRespondWith(
              status = 200,
              headers = Map.empty,
              body = """{"transactionId":240964973}""",
              matchingRules = bodyRegexRule("transactionId", "^[a-zA-Z0-9]{,20}$")
            )
        )

The results that I am seeing and are puzzling me are:

  • The matchingRules on the request are not being used to generate a request on the verifier, ie, the provider is called with an empty body.
  • The matching Rules on the request are not being used to check the body provided on the consumer contract test, ie, if I provide 0 or more than 20 characters the consumer tests won't fail.
  • The response matching Rules on the provider verification are ignored, ie, a match type doesn't error when the property is not being returned. A regex matcher that only accepts numbers doesn't error when the provider returns non-numeric values.

I think that I've read somewhere that the request matchingRules should be used as a stub for the verification of the provider and the matching rules of the response should be used as a comparison between the provider response and the contract.

My understanding of the matching rules for both request and the reply on the consumer side is that they are not used at all, wouldn't be good to check that the request being produced by the consumer is within the parameters expected?

Am I missing something on the setup or usage of Pact that would cause the consumer tests to no match on the request generated by the consumer and for the request sent to the provider to not be generated based on the request contract matching rules?

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

1 participant