Skip to content

Commit

Permalink
feat: enable --ignore option for can-i-deploy without a feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 3, 2021
1 parent e98895a commit bcc9dfe
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 23 deletions.
57 changes: 39 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,48 @@ Usage:
pact-broker can-i-deploy -a, --pacticipant=PACTICIPANT -b, --broker-base-url=BROKER_BASE_URL
Options:
-a, --pacticipant=PACTICIPANT # The pacticipant name. Use once for each pacticipant being checked.
-e, [--version=VERSION] # The pacticipant version. Must be entered after the --pacticipant that it relates to.
-l, [--latest=[TAG]] # Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag.
[--to=TAG] # This is too hard to explain in a short sentence. Look at the examples.
-b, --broker-base-url=BROKER_BASE_URL # The base URL of the Pact Broker
-u, [--broker-username=BROKER_USERNAME] # Pact Broker basic auth username
-p, [--broker-password=BROKER_PASSWORD] # Pact Broker basic auth password
-k, [--broker-token=BROKER_TOKEN] # Pact Broker bearer token
-o, [--output=OUTPUT] # json or table
# Default: table
-v, [--verbose], [--no-verbose] # Verbose output. Default: false
[--retry-while-unknown=TIMES] # The number of times to retry while there is an unknown verification result (ie. the provider verification is likely still running)
# Default: 0
[--retry-interval=SECONDS] # The time between retries in seconds. Use in conjuction with --retry-while-unknown
# Default: 10
-a, --pacticipant=PACTICIPANT
# The pacticipant name. Use once for each pacticipant being checked.
-e, [--version=VERSION]
# The pacticipant version. Must be entered after the --pacticipant that it relates to.
[--ignore=IGNORE]
# The pacticipant name to ignore. Use once for each pacticipant being ignored.
A specific version can be ignored by also specifying a --version after the pacticipant name option.
-l, [--latest=[TAG]]
# Use the latest pacticipant version. Optionally specify a TAG to use the
latest version with the specified tag.
[--to=TAG]
# This is too hard to explain in a short sentence. Look at the examples.
-o, [--output=OUTPUT]
# json or table
# Default: table
[--retry-while-unknown=TIMES]
# The number of times to retry while there is an unknown verification result
(ie. the provider verification is likely still running)
# Default: 0
[--retry-interval=SECONDS]
# The time between retries in seconds. Use in conjuction with --retry-while-unknown
# Default: 10
-b, --broker-base-url=BROKER_BASE_URL
# The base URL of the Pact Broker
-u, [--broker-username=BROKER_USERNAME]
# Pact Broker basic auth username
-p, [--broker-password=BROKER_PASSWORD]
# Pact Broker basic auth password
-k, [--broker-token=BROKER_TOKEN]
# Pact Broker bearer token
-v, [--verbose], [--no-verbose]
# Verbose output. Default: false
Description:
Returns exit code 0 or 1, indicating whether or not the specified pacticipant versions are compatible. Prints out the relevant
pact/verification details.
Returns exit code 0 or 1, indicating whether or not the specified application (pacticipant) versions are
compatible (ie. safe to deploy). Prints out the relevant pact/verification details, indicating any
missing or failed verification results.
The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_BASE_URL_USERNAME and PACT_BROKER_BASE_URL_PASSWORD may be used
The environment variables PACT_BROKER_BASE_URL, PACT_BROKER_USERNAME and PACT_BROKER_PASSWORD may be used
instead of their respective command line options.
```

Expand Down
79 changes: 79 additions & 0 deletions doc/pacts/markdown/Pact Broker Client - Pact Broker.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@

* [A request to create a webhook with every possible event type](#a_request_to_create_a_webhook_with_every_possible_event_type_given_the_'Pricing_Service'_and_'Condor'_already_exist_in_the_pact-broker) given the 'Pricing Service' and 'Condor' already exist in the pact-broker

* [A request to determine if Bar can be deployed with all Foo tagged prod, ignoring the verification for Foo version 3.4.5](#a_request_to_determine_if_Bar_can_be_deployed_with_all_Foo_tagged_prod,_ignoring_the_verification_for_Foo_version_3.4.5_given_provider_Bar_version_4.5.6_has_a_successful_verification_for_Foo_version_1.2.3_tagged_prod_and_a_failed_verification_for_version_3.4.5_tagged_prod) given provider Bar version 4.5.6 has a successful verification for Foo version 1.2.3 tagged prod and a failed verification for version 3.4.5 tagged prod

* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_already_exists_in_the_pact-broker) given the 'Pricing Service' already exists in the pact-broker

* [A request to get the Pricing Service](#a_request_to_get_the_Pricing_Service_given_the_'Pricing_Service'_does_not_exist_in_the_pact-broker) given the 'Pricing Service' does not exist in the pact-broker
Expand Down Expand Up @@ -1607,6 +1609,83 @@ Pact Broker will respond with:
}
}
```
<a name="a_request_to_determine_if_Bar_can_be_deployed_with_all_Foo_tagged_prod,_ignoring_the_verification_for_Foo_version_3.4.5_given_provider_Bar_version_4.5.6_has_a_successful_verification_for_Foo_version_1.2.3_tagged_prod_and_a_failed_verification_for_version_3.4.5_tagged_prod"></a>
Given **provider Bar version 4.5.6 has a successful verification for Foo version 1.2.3 tagged prod and a failed verification for version 3.4.5 tagged prod**, upon receiving **a request to determine if Bar can be deployed with all Foo tagged prod, ignoring the verification for Foo version 3.4.5** from Pact Broker Client, with
```json
{
"method": "get",
"path": "/matrix",
"query": "q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Btag%5D=prod&latestby=cvpv&ignore%5B%5D%5Bpacticipant%5D=Foo&ignore%5B%5D%5Bversion%5D=3.4.5"
}
```
Pact Broker will respond with:
```json
{
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"summary": {
"deployable": true,
"ignored": 1
},
"notices": [
{
"text": "some notice",
"type": "info"
}
],
"matrix": [
{
"consumer": {
"name": "Foo",
"version": {
"number": "1.2.3"
}
},
"provider": {
"name": "Bar",
"version": {
"number": "4.5.6"
}
},
"verificationResult": {
"success": true,
"_links": {
"self": {
"href": "http://result"
}
}
}
},
{
"consumer": {
"name": "Foo",
"version": {
"number": "3.4.5"
}
},
"provider": {
"name": "Bar",
"version": {
"number": "4.5.6"
}
},
"verificationResult": {
"success": false,
"_links": {
"self": {
"href": "http://result"
}
}
},
"ignored": true
}
]
}
}
```
<a name="a_request_to_get_the_Pricing_Service_given_the_&#39;Pricing_Service&#39;_already_exists_in_the_pact-broker"></a>
Given **the 'Pricing Service' already exists in the pact-broker**, upon receiving **a request to get the Pricing Service** from Pact Broker Client, with
```json
Expand Down
5 changes: 1 addition & 4 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class Broker < CustomThor

method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
method_option :version, required: false, aliases: "-e", desc: "The pacticipant version. Must be entered after the --pacticipant that it relates to."

if ENV.fetch("PACT_BROKER_FEATURES", "").include?("ignore")
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version."
end
method_option :ignore, required: false, desc: "The pacticipant name to ignore. Use once for each pacticipant being ignored. A specific version can be ignored by also specifying a --version after the pacticipant name option."
method_option :latest, required: false, aliases: "-l", banner: '[TAG]', desc: "Use the latest pacticipant version. Optionally specify a TAG to use the latest version with the specified tag."
method_option :to, required: false, banner: 'TAG', desc: "This is too hard to explain in a short sentence. Look at the examples.", default: nil
method_option :to_environment, required: false, banner: 'ENVIRONMENT', desc: "The environment into which the pacticipant(s) are to be deployed", default: nil, hide: true
Expand Down
88 changes: 88 additions & 0 deletions spec/pacts/pact_broker_client-pact_broker.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,94 @@
}
}
},
{
"description": "a request to determine if Bar can be deployed with all Foo tagged prod, ignoring the verification for Foo version 3.4.5",
"providerState": "provider Bar version 4.5.6 has a successful verification for Foo version 1.2.3 tagged prod and a failed verification for version 3.4.5 tagged prod",
"request": {
"method": "get",
"path": "/matrix",
"query": "q%5B%5D%5Bpacticipant%5D=Bar&q%5B%5D%5Bversion%5D=4.5.6&q%5B%5D%5Bpacticipant%5D=Foo&q%5B%5D%5Btag%5D=prod&latestby=cvpv&ignore%5B%5D%5Bpacticipant%5D=Foo&ignore%5B%5D%5Bversion%5D=3.4.5"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/hal+json;charset=utf-8"
},
"body": {
"summary": {
"deployable": true,
"ignored": 1
},
"notices": [
{
"text": "some notice",
"type": "info"
}
],
"matrix": [
{
"consumer": {
"name": "Foo",
"version": {
"number": "1.2.3"
}
},
"provider": {
"name": "Bar",
"version": {
"number": "4.5.6"
}
},
"verificationResult": {
"success": true,
"_links": {
"self": {
"href": "http://result"
}
}
}
},
{
"consumer": {
"name": "Foo",
"version": {
"number": "3.4.5"
}
},
"provider": {
"name": "Bar",
"version": {
"number": "4.5.6"
}
},
"verificationResult": {
"success": false,
"_links": {
"self": {
"href": "http://result"
}
}
},
"ignored": true
}
]
},
"matchingRules": {
"$.body.notices": {
"min": 1
},
"$.body.notices[*].*": {
"match": "type"
},
"$.body.matrix[0].verificationResult._links.self.href": {
"match": "type"
},
"$.body.matrix[1].verificationResult._links.self.href": {
"match": "type"
}
}
}
},
{
"description": "a request for the compatibility matrix for Foo version 1.2.3 and Bar version 4.5.6",
"providerState": "the pact for Foo version 1.2.3 has been verified by Bar version 4.5.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'pact_broker/client/can_i_deploy'

module PactBroker::Client
describe Matrix, :pact => true, skip: true do
describe Matrix, :pact => true do

include_context "pact broker"

Expand Down

0 comments on commit bcc9dfe

Please sign in to comment.