Verification - Provider change
Provider verification tasks performed on provider commits
Branches
Configuring the branch when publishing pacts
- Pact CLI
- Ruby
See here for full docs.
pact-broker publish ./pacts --consumer-app-version $GIT_COMMIT --branch $GIT_BRANCH
# or
pact-broker publish ./pacts --auto-detect-version-properties
See here for full docs.
# In Gemfile
gem "pact_broker-client"
# In Rakefile
require "pact_broker/client/tasks"
PactBroker::Client::PublicationTask.new do | task |
task.consumer_version = ENV["GIT_COMMIT"]
task.branch = ENV["GIT_BRANCH"]
end
Configuring the branch when publishing verification results
- Ruby provider-verifier CLI
- Ruby
See here for full docs.
pact-provider-verifier \
--provider "Example API" \
--provider-app-version $GIT_COMMIT \
--provider-version-branch $GIT_BRANCH \
...
See here for full docs.
# In spec/pact_helper.rb
Pact.service_provider "My Service Provider" do
app_version ENV["GIT_COMMIT"]
app_version_branch ENV["GIT_BRANCH"]
end
Consumer version selectors
You can checkout code-snippets below, but here are some links to either documentation, or source code, from the respective languages, around their use of consumer version selectors. Ideally all languages should support raw json version selectors, to allow for extensiblity in the future.
- JavaScript
- Java
- Gradle
- Ruby
- Python - Takes raw json consumer_version_selectors
- C#
- Golang
Consumer version selectors - Code examples with branches
Verifying the latest development, test and master pacts
This is the most common use case.
- We recommend using
deployedOrReleased
to return the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment, this allows the provider to not know that detail and let the Pact broker take care of it for you)- alternatively you can target just
deployed
or justreleased
consumers acrossall
environments , or consumers only in specifiedenvironments
.
- alternatively you can target just
- We recommend using
mainBranch
to return the pacts associated with any consumers configuredmainBranch
property (your consumer may have the branchmain
,master
ordevelop
, this allows the provider to not know that detail and let the Pact broker take care of it for you) - The shown selectors, will target for the provider
- any pacts for the consumer associated with their configured
mainBranch
property - any pacts for the consumers, deployed to
any
environment- This if filtered by only pacts
deployed
orreleased
to thetest
/production
environments. - If this consumer/provider pair, has an additional environment
staging
, it would not be picked up, due to the namedtest
/production
environments. Removing these conditions, will return any pacts, deployed or released to any environment, which is the recommended setup for the majority of cases. (coupled with enabling pending pacts.)
- This if filtered by only pacts
- any pacts for the consumer associated with their configured
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ....
consumerVersionSelectors: [
{
mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
{
deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
{
environment: 'test', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
},
{
environment: 'production', // Normally, this would not be needed, as it is recommended to verify the pacts for all currently deployed/currently supported released versions.
},
],
};
@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
return new SelectorBuilder()
.mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property
.deployedOrReleased(); // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
.deployedTo('test'); // Normally, this would not be needed, Any versions currently deployed to the specified environment.
.deployedTo('production'); // Normally, this would not be needed, Any versions currently deployed to the specified environment.
.environment('test') // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
.environment('production') // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
}
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
withSelectors {
mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property
deployedOrReleased() // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
deployedTo('test') // Normally, this would not be needed, Any versions currently deployed to the specified environment.
deployedTo('test') // Normally, this would not be needed, Any versions currently deployed to the specified environment.
environment('test') // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
environment('production') // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
}
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property
{ deployedOrReleased: true }, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
{ deployed: "test" }, # Normally, this would not be needed, Any versions currently deployed to the specified environment.
{ deployed: "production" } # Normally, this would not be needed, Any versions currently deployed to the specified environment.
{ environment: "test" }, # Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
{ environment: "production" } # Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
{"deployedOrReleased": True}, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
{"deployed": "test"}, # Normally, this would not be needed, Any versions currently deployed to the specified environment.
{"deployed": "production"}, # Normally, this would not be needed, Any versions currently deployed to the specified environment.
{"environment": "test"}, # Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
{"environment": "production"}, # Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
],
# ...
)
IPactVerifier verifier = new PactVerifier(config);
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
.WithPactBrokerSource(new Uri("https://broker.example.org"), options =>
{
options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property
new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // Normally, this would not be needed, Any versions currently deployed to the specified environment.
new ConsumerVersionSelector { Deployed = true, Environment = "production" }, // Normally, this would not be needed, Any versions currently deployed to the specified environment.
new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "test" }, // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production" }, // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
)
.PublishResults(version, results =>
{
results.ProviderBranch(branch)
.BuildUri(new Uri(buildUri));
});
})
.WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
.Verify();
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
types.ConsumerVersionSelector{
DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
types.ConsumerVersionSelector{
Deployed: "test", // Normally, this would not be needed, Any versions currently deployed to the specified environment.
},
types.ConsumerVersionSelector{
Deployed: "production", // Normally, this would not be needed, Any versions currently deployed to the specified environment.
},
types.ConsumerVersionSelector{
Environment: "test", // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
},
types.ConsumerVersionSelector{
Environment: "production", // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment.
},
},
// ...
})
Using a matching branch for coordinated branch development
Dynamically determine the current branch of the provider, see if there is a matching pact for that branch.
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
//...
consumerVersionSelectors: [
{
matchingBranch: true, // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
},
{
mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
{
deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
],
};
// Requires Pact-JVM 4.1.10 or later
@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
return new SelectorBuilder()
.matchingBranch(); // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
.mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property
.deployedOrReleased(); // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
}
// Requires Pact-JVM 4.1.10 or later
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
withSelectors {
matchingBranch() // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property
deployedOrReleased() // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
}
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ matchingBranch: true }, # Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
{ mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property
{ deployedOrReleased: true }, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"matchingBranch": True}, # Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
{"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
{"deployedOrReleased": True}, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
],
# ...
)
IPactVerifier verifier = new PactVerifier(config);
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
.WithPactBrokerSource(new Uri("https://broker.example.org"), options =>
{
options.ConsumerVersionSelectors(new ConsumerVersionSelector { MatchingBranch = true }, // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property
)
.PublishResults(version, results =>
{
results.ProviderBranch(branch)
.BuildUri(new Uri(buildUri));
});
})
.WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
.Verify();
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
MatchingBranch: true, // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook
},
types.ConsumerVersionSelector{
MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
types.ConsumerVersionSelector{
DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
},
// ...
})
Verifying pacts where the consumer is a mobile application
Verify the pacts for the latest master
and test
versions, and all production
versions of "my-mobile-consumer".
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ....
consumerVersionSelectors: [
{
mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
{
deployed: 'test', // only the latest deployed version to test
},
{
deployedOrReleased: 'production', // all deployed or released versions in production
},
],
};
@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
return new SelectorBuilder()
.mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property
.deployedTo('test'); // only the latest deployed version to test
.environment('production') // all deployed or released versions in production
}
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
withSelectors {
mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property
deployedTo('test') // only the latest deployed version to test
environment('production') // all deployed or released versions in production
}
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property
{ deployed: "test" }, # only the latest deployed version to test
{ environment: "production" } # all deployed or released versions in production
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
{"deployed": "test"}, # only the latest deployed version to test
{"environment": "production"}, # all deployed or released versions in production
],
# ...
)
IPactVerifier verifier = new PactVerifier(config);
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
.WithPactBrokerSource(new Uri("https://broker.example.org"), options =>
{
options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property
new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // only the latest deployed version to test
new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production" }, // all deployed or released versions in production
)
.PublishResults(version, results =>
{
results.ProviderBranch(branch)
.BuildUri(new Uri(buildUri));
});
})
.WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
.Verify();
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
types.ConsumerVersionSelector{
Deployed: "test", // only the latest deployed version to test
},
types.ConsumerVersionSelector{
Environment: "production", // all deployed or released versions in production
},
},
// ...
})
Verifying a pacts where one consumer is a mobile application
Verify the latest production
version of all consumers, and all production
versions of "my-mobile-consumer". Note that the pacts are deduplicated, so despite being included by 2 selectors, the verification of the latest production pact for "my-mobile-consumer" will only run once.
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ....
consumerVersionSelectors: [
{
mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
{
deployed: 'test', // Verify the latest deployed `test` version of all consumers
},
{
deployed: 'production', // Verify the latest deployed `production` version of all consumers
},
{
deployedOrReleased: 'production', // Verify all deployed or released `production` versions of my-mobile-consumer
consumer: 'my-mobile-consumer'
},
],
};
@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
return new SelectorBuilder()
.mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property
.deployedTo('test'); // Verify the latest deployed `test` version of all consumers
.deployedTo('production'); // Verify the latest deployed `production` version of all consumers
.rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') // Verify all deployed or released `production` versions of my-mobile-consumer
}
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
withSelectors {
mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property
deployedTo('test') // Verify the latest deployed `test` version of all consumers
deployedTo('production') // Verify the latest deployed `production` version of all consumers
rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') // Verify all deployed or released `production` versions of my-mobile-consumer
}
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property
{ deployed: "test" }, # Verify the latest deployed `test` version of all consumers
{ deployed: "production" }, # Verify the latest deployed `production` version of all consumers
{ deployedOrReleased: "production", consumer: "my-mobile-consumer" } # Verify all deployed or released `production` versions of my-mobile-consumer
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
{"deployed": "test"}, # Verify the latest deployed `test` version of all consumers
{"deployed": "production"}, # Verify the latest deployed `production` version of all consumers
{"environment": "production", "consumer": "my-mobile-consumer" }, # Verify all deployed or released `production` versions of my-mobile-consumer
],
# ...
)
IPactVerifier verifier = new PactVerifier(config);
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
.WithPactBrokerSource(new Uri("https://broker.example.org"), options =>
{
options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property
new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // Verify the latest deployed `test` version of all consumers
new ConsumerVersionSelector { Deployed = true, Environment = "production" }, // Verify the latest deployed `production` version of all consumers
new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production", Consumer = "my-mobile-consumer" }, // Verify all deployed or released `production` versions of my-mobile-consumer
)
.PublishResults(version, results =>
{
results.ProviderBranch(branch)
.BuildUri(new Uri(buildUri));
});
})
.WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
.Verify();
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
types.ConsumerVersionSelector{
Deployed: "test", // Verify the latest deployed `test` version of all consumers
},
types.ConsumerVersionSelector{
Deployed: "production", // Verify the latest deployed `production` version of all consumers
},
types.ConsumerVersionSelector{
Environment: "production", // Verify all deployed or released `production` versions of my-mobile-consumer
Consumer: "my-mobile-consumer",
},
},
// ...
})
Verifying the overall latest pact for each consumer
Verifying the overall latest pact for each consumer is syntactically possible, but not recommended, as pacts for different branches of the consumer may overwrite each other as the current latest.
You can do this by setting latest: true
, however as this is wholly unrecommended, we instead show the minimum ideal requirement, to cover the latest pacts for
- any consumer that is registered with the provider
- the latest pact for any environment the consumer is
deployed
to - the latest pact, for any environment in the consumer is
released
to - the latest pact, for the consumer configured
mainBranch
- the latest pact for any environment the consumer is
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ....
consumerVersionSelectors: [
{
mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
{
deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
],
};
@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
return new SelectorBuilder()
.mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property
.deployedOrReleased(); // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
}
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
withSelectors {
mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property
deployedOrReleased() // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
}
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property
{ deployedOrReleased: true }, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property
{"deployedOrReleased": True}, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
],
# ...
)
IPactVerifier verifier = new PactVerifier(config);
verifier.ServiceProvider("My Provider", this.fixture.ServerUri)
.WithPactBrokerSource(new Uri("https://broker.example.org"), options =>
{
options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property
new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
)
.PublishResults(version, results =>
{
results.ProviderBranch(branch)
.BuildUri(new Uri(buildUri));
});
})
.WithProviderStateUrl(new Uri(this.fixture.ServerUri, "/provider-states"))
.Verify();
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property
},
types.ConsumerVersionSelector{
DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment.
},
},
// ...
})
Consumer version selectors - Code examples with tags
Verifying the latest development, test and master pacts
This is the most common use case.
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ....
consumerVersionSelectors: [
{
tag: "master",
latest: true,
},
{
tag: "test",
latest: true,
},
{
tag: "production",
latest: true,
},
],
};
@PactBroker(
host="pactbroker.local",
port="8080",
consumerVersionSelectors={
@VersionSelector(tag = "master"),
@VersionSelector(tag = "test"),
@VersionSelector(tag = "production")
}
)
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
selectors = latestTags('master', 'test', 'production')
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ tag: "main", latest: true },
{ tag: "test", latest: true },
{ tag: "production", latest: true }
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"tag": "main", "latest": True},
{"tag": "test", "latest": True},
{"tag": "production", "latest": True},
],
# ...
)
var pactVerifier = new PactVerifier(new PactVerifierConfig())
.ProviderState($"providerServiceBaseUri/provider-states")
.ServiceProvider("ProviderPacticipantName", "providerServiceBaseUri")
.HonoursPactWith("ConsumerPacticipantName")
.PactBroker(
"http://pact-broker",
consumerVersionSelectors: new List<VersionTagSelector>
{
new VersionTagSelector("master", latest: true),
new VersionTagSelector("test", latest: true),
new VersionTagSelector("production", latest: true)
});
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
Tag: "master",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "test",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "production",
Latest: true,
},
},
// ...
})
Using a fallback tag for coordinated branch development
Dynamically determine the current branch of the provider, see if there is a matching pact for that branch, fallback to the master
pact if none exists. This approach is not longer recommended - see the note on the fallbackTag
at the top of the page.
- Javascript
- Java
- Gradle
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
//...
consumerVersionSelectors: [
{
tag: process.env.GIT_BRANCH,
fallbackTag: "master",
latest: true,
},
{
tag: "test",
latest: true,
},
{
tag: "production",
latest: true,
},
],
};
// Requires Pact-JVM 4.1.10 or later
@PactBroker(
host="pactbroker.local",
port="8080",
consumerVersionSelectors={
@VersionSelector(tag = "${GIT_BRANCH}", fallbackTag = "master"),
@VersionSelector(tag = "test"),
@VersionSelector(tag = "production")
}
)
// Requires Pact-JVM 4.1.10 or later
pact {
serviceProviders {
'Your Service' {
providerVersion = { '1.2.3' }
fromPactBroker {
selectors = latestTags(fallbackTag: 'master', System.getenv('GIT_BRANCH'))
}
}
}
}
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ tag: ENV["GIT_BRANCH"], fallback_tag: "main", latest: true },
{ tag: "test", latest: true },
{ tag: "production", latest: true }
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"tag": os.environ.get("GIT_BRANCH"), "fallback_tag": "main", "latest": True},
{"tag": "test", "latest": True},
{"tag": "production", "latest": True},
],
# ...
)
var pactVerifier = new PactVerifier(new PactVerifierConfig())
.ProviderState($"providerServiceBaseUri/provider-states")
.ServiceProvider("ProviderPacticipantName", "providerServiceBaseUri")
.HonoursPactWith("ConsumerPacticipantName")
.PactBroker(
"http://pact-broker",
consumerVersionSelectors: new List<VersionTagSelector>
{
new VersionTagSelector(Environment.GetEnvironmentVariable("GIT_BRANCH"), fallbackTag: "master", latest: true),
new VersionTagSelector("test", latest: true),
new VersionTagSelector("production", latest: true)
});
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
Tag: os.Getenv("GIT_BRANCH"),
FallbackTag: "master",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "test",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "production",
Latest: true,
},
},
// ...
})
Verifying pacts where the consumer is a mobile application
Verify the pacts for the latest master
and test
versions, and all production
versions of "my-mobile-consumer".
- Javascript
- Java
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ...
consumerVersionSelectors: [
{
tag: "master",
latest: true,
},
{
tag: "test",
latest: true,
},
{
tag: "production",
},
],
};
@PactBroker(
host="pactbroker.local",
port="8080",
consumerVersionSelectors={
@VersionSelector(tag = "master"),
@VersionSelector(tag = "test"),
@VersionSelector(tag = "production", latest = false)
})
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ tag: "main", latest: true },
{ tag: "test", latest: true },
{ tag: "production" }
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"tag": "main", "latest": True},
{"tag": "test", "latest": True},
{"tag": "production"},
],
# ...
)
IPactVerifier pactVerifier = new PactVerifier(new PactVerifierConfig())
.ProviderState($"providerServiceBaseUri/provider-states")
.ServiceProvider("ProviderPacticipantName", "providerServiceBaseUri")
.HonoursPactWith("ConsumerPacticipantName")
.PactBroker(
"http://pact-broker",
consumerVersionSelectors: new List<VersionTagSelector>
{
new VersionTagSelector("master", latest: true),
new VersionTagSelector("test", latest: true),
new VersionTagSelector("production")
});
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
Tag: os.Getenv("GIT_BRANCH"),
FallbackTag: "master",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "test",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "production",
Latest: false,
},
},
// ...
})
Verifying a pacts where one consumer is a mobile application
Verify the latest production
version of all consumers, and all production
versions of "my-mobile-consumer". Note that the pacts are deduplicated, so despite being included by 2 selectors, the verification of the latest production pact for "my-mobile-consumer" will only run once.
- Javascript
- Java
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ...
consumerVersionSelectors: [
{
tag: "master",
latest: true,
},
{
tag: "test",
latest: true,
},
{
tag: "production",
latest: true,
},
{
tag: "production",
consumer: "my-mobile-consumer",
},
],
};
// Requires Pact-JVM 4.1.8 or later
@PactBroker(
host="pactbroker.local",
port="8080",
consumerVersionSelectors={
@VersionSelector(tag = "master"),
@VersionSelector(tag = "test"),
@VersionSelector(tag = "production"),
@VersionSelector(tag = "production", consumer = "my-mobile-consumer")
}
)
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ tag: "main", latest: true },
{ tag: "test", latest: true },
{ tag: "production", latest: true },
{ tag: "production", consumer: "my-mobile-consumer" }
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"tag": "main", "latest": True},
{"tag": "test", "latest": True},
{"tag": "production", "latest": True},
{"tag": "production", "consumer": "my-mobile-consumer"},
],
# ...
)
IPactVerifier pactVerifier = new PactVerifier(new PactVerifierConfig())
.ProviderState($"providerServiceBaseUri/provider-states")
.ServiceProvider("ProviderPacticipantName", "providerServiceBaseUri")
.HonoursPactWith("ConsumerPacticipantName")
.PactBroker(
"http://pact-broker",
consumerVersionSelectors: new List<VersionTagSelector>
{
new VersionTagSelector("master", latest: true),
new VersionTagSelector("test", latest: true),
new VersionTagSelector("production", latest: true),
new VersionTagSelector("production", "my-mobile-consumer")
});
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
Tag: os.Getenv("GIT_BRANCH"),
FallbackTag: "master",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "test",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "production",
Latest: true,
},
types.ConsumerVersionSelector{
Tag: "production",
Consumer: "my-mobile-consumer",
},
},
// ...
})
Verifying the overall latest pact for each consumer
This is syntactically possible, but not recommended, as pacts for different branches of the consumer may overwrite each other as the current latest.
- Javascript
- Java
- Ruby
- Python
- C#
- Golang
const verificationOptions = {
// ...
consumerVersionSelectors: [
{
latest: true,
},
],
};
// Requires Pact-JVM 4.1.8 or later
@PactBroker(
host="pactbroker.local",
port="8080",
consumerVersionSelectors={ @VersionSelector(latest = "true") }
)
Pact.service_provider "Your provider" do
honours_pacts_from_pact_broker do
pact_broker_base_url "..."
consumer_version_selectors [
{ latest: true }
]
end
end
verifier = Verifier(
provider="Your provider",
broker_url="...",
consumer_version_selectors=[
{"latest": True},
],
# ...
)
IPactVerifier pactVerifier = new PactVerifier(new PactVerifierConfig())
.ProviderState($"providerServiceBaseUri/provider-states")
.ServiceProvider("ProviderPacticipantName", "providerServiceBaseUri")
.HonoursPactWith("ConsumerPacticipantName")
.PactBroker(
"http://pact-broker",
consumerVersionSelectors: new List<VersionTagSelector>
{
new VersionTagSelector("", latest: true)
});
pact.VerifyProvider(t, types.VerifyRequest{
ConsumerVersionSelectors: []types.ConsumerVersionSelector{
types.ConsumerVersionSelector{
Latest: true,
},
},
// ...
})
Verifying pacts
Examples
- Javascript
- Ruby
Using branches and environments
const verificationOptions = {
// ....
provider: "example-provider",
pactBrokerUrl: "http://test.pactflow.io",
consumerVersionSelectors: [
{
mainBranch: true
},
{
matchingBranch: true
},
{
deployedOrReleased: true
}
],
enablePending: true,
...(process.env.GIT_BRANCH === "main"
? {
includeWipPactsSince: "2020-01-01",
}
: {})
// used when publishing verification results
publishVerificationResult: process.env.CI === "true", //only publish from CI
providerVersion: process.env.GIT_COMMIT, //use the appropriate env var from your CI system
providerVersionBranch: process.env.GIT_BRANCH, //use the appropriate env var from your CI system
}
Using tags (this approach is now superseded by branches and environments)
const verificationOptions = {
// ....
provider: "example-provider",
pactBrokerUrl: "http://test.pactflow.io",
consumerVersionSelectors: [
{
tag: "main",
latest: true
},
{
tag: process.env.GIT_BRANCH,
latest: true
},
{
tag: "test",
latest: true
},
{
tag: "production",
latest: true
}
],
enablePending: true,
includeWipPactsSince: process.env.GIT_BRANCH === "main" ? "2020-01-01" : undefined,
// used when publishing verification results
publishVerificationResult: process.env.CI === "true", //only publish from CI
providerVersion: process.env.GIT_COMMIT, //use the appropriate env var from your CI system
providerVersionTags: process.env.GIT_BRANCH ? [process.env.GIT_BRANCH] : [],
}
Using branches and environments
# The git commands are just for local testing, not needed for real CI
provider_version = ENV['GIT_COMMIT'] || `git rev-parse --verify HEAD`.strip
provider_branch = ENV['GIT_BRANCH'] || `git name-rev --name-only HEAD`.strip
publish_results = ENV['CI'] == 'true' # results should only be published from CI
# choose the appropriate credentials for your broker
credentials = {
username: ENV['PACT_BROKER_USERNAME'],
password: ENV['PACT_BROKER_PASSWORD'],
token: ENV['PACT_BROKER_TOKEN']
}.compact
Pact.service_provider "example-provider" do
app_version provider_version
app_version_branch provider_branch
publish_verification_results publish_results
honours_pacts_from_pact_broker do
pact_broker_base_url 'http://test.pactflow.io', credentials
consumer_version_selectors [
{ main_branch: true },
{ matching_branch: true },
{ deployed_or_released: true }
]
enable_pending true
include_wip_pacts_since provider_branch == "main" ? "2020-01-01" : nil
end
end
Using tags (this approach is now superseded by branches and environments)
# The git commands are just for local testing, not needed for real CI
provider_version = ENV['GIT_COMMIT'] || `git rev-parse --verify HEAD`.strip
provider_branch = ENV['GIT_BRANCH'] || `git name-rev --name-only HEAD`.strip
publish_results = ENV['CI'] == 'true' # results should only be published from CI
# choose the appropriate credentials for your broker
credentials = {
username: ENV['PACT_BROKER_USERNAME'],
password: ENV['PACT_BROKER_PASSWORD'],
token: ENV['PACT_BROKER_TOKEN']
}
Pact.service_provider "example-provider" do
app_version provider_version
app_version_tags [provider_branch]
publish_verification_results publish_results
honours_pacts_from_pact_broker do
pact_broker_base_url 'http://test.pactflow.io', credentials
consumer_version_selectors [
{ tag: 'main', latest: true },
{ tag: provider_branch, latest: true },
{ tag: 'test', latest: true },
{ tag: 'production', latest: true }
]
enable_pending true
include_wip_pacts_since provider_branch == "main" ? "2020-01-01" : nil
end
end