I have two projects in the same repo, with completely separate directory structures (consumer in /test-consumer
, provider in /app
).
The consumer check outputs a JSON Pact file in /test-consumer/build/pacts
, as expected by
dependencies { test { systemProperties['pact.rootDir'] = "$buildDir/pacts" } }
I then copy the file into /app/build/pacts/
, and put this same systemProperties
line into my provider's build.gradle
.
The sample project that I'm plagiarising from is using a Pact broker, so I guessed I can take that out, and replace it with the rootDir
, but it's not working. This is what I get:
WARNING: There are no consumers to verify for provider 'Coffee Ordering Provider'
So, it seems like it's finding the Pact files, but can't find a provider+consumer pair in any of them.
TL;DR: What am I doing wrong?
Here are some code bits to help:
dependencies {
...
test { systemProperties['pact.rootDir'] = "$buildDir/pacts" }
}
pact {
serviceProviders {
'Coffee Ordering Provider' {
port = 8080
startProviderTask = startProvider
terminateProviderTask = stopProvider
stateChangeUrl = url('http://localhost:8080/pactStateChange')
}
}
}
You are getting that warning because you have not told the pact plugin where to find the pact files. For pacts in a directory, add the following:
pact {
serviceProviders {
'Coffee Ordering Provider' {
port = 8080
startProviderTask = startProvider
terminateProviderTask = stopProvider
stateChangeUrl = url('http://localhost:8080/pactStateChange')
hasPactsWith('Coffee Ordering Consumers') {
// Will define a consumer for each pact file in the directory.
// Consumer name is read from contents of pact file
pactFileLocation = file("$buildDir/pacts")
}
}
}
}
Just a note that you were setting the pact.rootDir
for all tests, but the pact verification does not run as a test.