Provider Not Registering Interaction

179 views Asked by At

I'm using the Pact Go implementation to try out contract testing. I've made a provider test that isn't working because I need to mock out my service's request to Twilio.

I've made one Pact object for the contract between my consumer and this provider, and then another one called twilioPact for the contract between my provider and Twilio. I've added an interaction for the POST to the Twilio endpoint, but in the pact.log I'm not seeing it get registered. My test is making the request correctly, but there's no interaction registered for it so I get the 500 error from the mock server.

Does anyone have any experience using Pact with a 'provider' that is also a 'consumer'?

EDIT: After talking with Matt Fellows I was informed that I was using Pact incorrectly, and shouldn't be trying to run a mock service while running a provider verification. I had suspected as much, but none of the examples I had seen were for a provider that had a dependency. I was able to get my provider verification to work by writing a consumer test and passing the generated pact file to the pact-stub-service to act as the mock to Twilio.

1

There are 1 answers

0
Matthew Fellows On BEST ANSWER

Here's a few things to consider:

  1. It's better to have two separate contract tests between your client <-> Twilio Adapter, and Twilio Adapter <-> Twilio. It's possible to do what you're doing, but it will make the tests more complicated and probably harder to read/comprehend. Testing them in isolation gives you much more control.
  2. When doing the former contract test, rather then daisy chain another pact mock service for your Twilio Adapter's (Provider) dependency (Twilio), you're best using standard mock/stub tooling for this job - either code based mocks/doubles, service doubles (e.g. Mountebank) or the stub server shipped with Pact [1]. Don't forget you will get to validate these assumptions with the other contract test, so you're safe to do this.
  3. It's possible that because you have two mock servers running (one to mock the Twilio Adapter and another to mock Twilio) that your requests are being sent to the same mock service, and getting all tangled up

[1] Here is are the list of binaries etc. that are shipped with pact-go:

    tree -L 3 /path/to/pact-go

    .
    ├── pact
    │   ├── README.md
    │   ├── bin
    │   │   ├── pact-broker
    │   │   ├── pact-mock-service
    │   │   ├── pact-provider-verifier
    │   │   ├── pact-publish
    │   │   └── pact-stub-service
    │   └── lib
    │       ├── app
    │       ├── ruby
    │       └── vendor
    └── pact-go