Hey all, does anyone know how to add multiple pact...
# pactflow
n
Hey all, does anyone know how to add multiple pact tests to a consumer as well a provider? Meaning, if a provider services several different consumers how would that look like? And if a consumer has several different providers how would that look like?
h
Generally speaking, a consumer can initiate a pact with any provider. The provider can decide or not decide to verify. So if consumer A and consumer B use provider Z api for GetUser, then great, now provider Z knows how its api is being used by consumers. And it might possibly be the same exact usage, but provider Z is at least aware. When defining a pact test as a consumer, one of the arguments is the ProviderName. So consumer A can have a pact with provider Z and provider Y. If using a broker, these pacts are published and discoverable to the provider. They are also pending until they are ultimately implemented and verified by the provider Just in case you are new to pact, I would suggest going thru some tutorials if you have not yet. There is lots of great stuff documented that helped me. I found the pact-go tutorial super easy to follow.
🙌 1
🙏 1
m
Exactly! So basically on the consumer side it's just another set of tests for the consumer to write, but in the setup you specify a different provider. On the provider side, it's just a matter of selecting pacts from the broker. The CI/CD workshop should give advice on this. Usually you would discover all pacts for consumers deployed to production, and the latest version associated with their main branches. This way new consumers can come on board without needing to change config
n
Yes so I do understand all of that. But what i'm unclear about is if I have a consumer that uses 10 different endpoints from the same provider, how would we have something like that work? Would there be multiple pact files on the provider side to separate each endpoint being tested? I guess i'm just a little unclear on the actual folder and file structure of what happens when we are testing a microservice with many api endpoints and there are several different consumers that each use several of those apis. On the consumer side I think i'm clear that they simply make the pact test and set the provider name, but on the provider side im not really sure how that looks like. I assumed that a provider would be the entire microservice.
h
I’m guessing if you are interested in organizing pact files for a provider, then you’re not using a broker such as pactflow. I haven’t done that since the tutorial, but if I recall the generated file is [consumer]-[provider].json. A flat folder structure seems sufficient, and all pacts for the consumer’s integration with the provider end up in the same file. Keep it simple.
n
Oh no I am using pactflow. I just mean, right now I have one contract with 2 interactions. That one contract is between one consumer and one provider and for one api endpoint. If I wanted to add another api endpoint to test, from my understanding I would need to create another consumer pact test (which make sense to me) but then what do I do on the provider side? Make another pact file that verifies that endpoint? I can send actual files etc. soon
m
The consumer makes the pact file. I think you mean on the provider side do you need a separate test file? No, it should just be a single verification test suite that collects all pacts for all consumers
n
Ah okay but if I have a microservice set as a provider, wouldn't that one file be extremely long to be able to verify all kinds of different apis with different states for each and every api? Maybe i'm overthinking it..
m
Ah okay but if I have a microservice set as a provider, wouldn’t that one file be extremely long to be able to verify all kinds of different apis with different states for each and every api? Maybe i’m overthinking it..
You might be! I’d say start simple and see how far you go. If it gets unweildly, you can always split the states out into other files to help manage it.
You can definitely create a separate verification suite per consumer if you want, but I’d advise against it.