From bcc9dfeee14953879bdcb17e68216fb0d8b77f98 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 3 Jun 2021 16:29:05 +1000 Subject: [PATCH] feat: enable --ignore option for can-i-deploy without a feature toggle --- README.md | 57 ++++++++---- .../Pact Broker Client - Pact Broker.md | 79 +++++++++++++++++ lib/pact_broker/client/cli/broker.rb | 5 +- .../pacts/pact_broker_client-pact_broker.json | 88 +++++++++++++++++++ .../pact_broker_client_matrix_ignore_spec.rb | 2 +- 5 files changed, 208 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index fcbb0010..fd07ca88 100644 --- a/README.md +++ b/README.md @@ -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. ``` diff --git a/doc/pacts/markdown/Pact Broker Client - Pact Broker.md b/doc/pacts/markdown/Pact Broker Client - Pact Broker.md index 57786c69..6275ed31 100644 --- a/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +++ b/doc/pacts/markdown/Pact Broker Client - Pact Broker.md @@ -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 @@ -1607,6 +1609,83 @@ Pact Broker will respond with: } } ``` + +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 + } + ] + } +} +``` 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 diff --git a/lib/pact_broker/client/cli/broker.rb b/lib/pact_broker/client/cli/broker.rb index 6f16c8b5..7aa7632c 100644 --- a/lib/pact_broker/client/cli/broker.rb +++ b/lib/pact_broker/client/cli/broker.rb @@ -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 diff --git a/spec/pacts/pact_broker_client-pact_broker.json b/spec/pacts/pact_broker_client-pact_broker.json index 10a46886..da098c83 100644 --- a/spec/pacts/pact_broker_client-pact_broker.json +++ b/spec/pacts/pact_broker_client-pact_broker.json @@ -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", diff --git a/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb b/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb index ad12bfc4..81a95c73 100644 --- a/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +++ b/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb @@ -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"