pact_broker-client 1.8.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +0 -17
  3. data/CHANGELOG.md +28 -0
  4. data/RELEASING.md +3 -14
  5. data/Rakefile +6 -1
  6. data/lib/pact_broker/client/base_client.rb +13 -1
  7. data/lib/pact_broker/client/can_i_deploy.rb +2 -3
  8. data/lib/pact_broker/client/cli/broker.rb +19 -8
  9. data/lib/pact_broker/client/cli/version_selector_options_parser.rb +5 -4
  10. data/lib/pact_broker/client/git.rb +15 -0
  11. data/lib/pact_broker/client/matrix.rb +17 -3
  12. data/lib/pact_broker/client/matrix/json_formatter.rb +2 -2
  13. data/lib/pact_broker/client/matrix/text_formatter.rb +3 -3
  14. data/lib/pact_broker/client/version.rb +1 -1
  15. data/pact-broker-client.gemspec +2 -3
  16. data/script/publish-pact.sh +1 -0
  17. data/script/release.sh +7 -0
  18. data/spec/integration/can_i_deploy_spec.rb +32 -0
  19. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +2 -2
  20. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +9 -1
  21. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +25 -0
  22. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +17 -14
  23. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +2 -2
  24. data/spec/lib/pact_broker/client/matrix_spec.rb +2 -1
  25. data/spec/pacts/pact_broker_client-pact_broker.json +272 -131
  26. data/spec/service_providers/pact_broker_client_matrix_spec.rb +89 -17
  27. data/spec/service_providers/pact_helper.rb +1 -0
  28. data/spec/support/matrix.json +26 -21
  29. data/spec/support/matrix.txt +1 -1
  30. metadata +11 -24
  31. data/Appraisals +0 -6
  32. data/gemfiles/default.gemfile +0 -7
  33. data/gemfiles/default.gemfile.lock +0 -106
  34. data/gemfiles/ruby_under_22.gemfile +0 -8
  35. data/gemfiles/ruby_under_22.gemfile.lock +0 -105
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06c73ab8a4906ce7f19c0239159954dc0dabafe8
4
- data.tar.gz: bfb34a47d2bdad5ce202fd87a8ceb9528744a2af
3
+ metadata.gz: ca92e53e6aab9983ef939c9582e6ac0359ca8259
4
+ data.tar.gz: 4497c279c270dd495633134a1203a5ff84caeb30
5
5
  SHA512:
6
- metadata.gz: 1c26067119ce4860e20625220ac490e02456d8f60816b12ba59857dd1f89778fa1b8e009e82adf57b5f213ad535357ce781b32c41b892120ba15067e24c6d1e7
7
- data.tar.gz: fbcb42c1b2ad4794e9f82e5dbea3703b816e62d4a2019c2e4d41f7d7b974e9afc3419fb17184ce49fec1bb3ba63c89aa33bdc3a7497947fc3c9694f4c1684c9e
6
+ metadata.gz: 24a2de802420ad8fbd99085b3a12ac34666334991bfc379f968a055f2b4072892cec8ca12a09fcf7536eaf64310f57a727328542c8ae9fde3063f020f31d7731
7
+ data.tar.gz: 44faf6be7105518d0432f09834c610a9ab77e55d0b760c2eb8f8b983661b435ffb5dc9198b8ad665b0034439f2284e67838008da67430e576f18d286aa5b6373
data/.travis.yml CHANGED
@@ -1,22 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.8
4
3
  - 2.2.4
5
4
  - 2.3.1
6
5
  - 2.4.1
7
- gemfile:
8
- - gemfiles/default.gemfile
9
- - gemfiles/ruby_under_22.gemfile
10
- matrix:
11
- exclude:
12
- # rack 2.0 and activesupport 5.0 no longer support ruby under 2.2.
13
- - rvm: 2.0.0
14
- gemfile: gemfiles/default.gemfile
15
- - rvm: 2.1.8
16
- gemfile: gemfiles/default.gemfile
17
- - rvm: 2.2.4
18
- gemfile: gemfiles/ruby_under_22.gemfile
19
- - rvm: 2.3.1
20
- gemfile: gemfiles/ruby_under_22.gemfile
21
- - rvm: jruby-9.0.5.0
22
- gemfile: gemfiles/ruby_under_22.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ <a name="v1.9.0"></a>
2
+ ### v1.9.0 (2017-10-30)
3
+
4
+
5
+ #### Features
6
+
7
+ * **cli**
8
+ * add option to --tag-with-git-branch when publishing pacts ([484d5b8](/../../commit/484d5b8))
9
+
10
+ * **can-i-deploy**
11
+ * raise error when no --version is supplied for a --pacticipant ([0f3bfea](/../../commit/0f3bfea))
12
+ * change --name to --pacticipant ([d5d23bc](/../../commit/d5d23bc))
13
+ * include full response body in json output ([216bfdc](/../../commit/216bfdc))
14
+ * use array of query params for matrix ([314e2e2](/../../commit/314e2e2))
15
+
16
+ * **what-can-i-deploy**
17
+ * add success param to matrix query ([40adb2e](/../../commit/40adb2e))
18
+
19
+ * handle hash of errors in response ([fff32c2](/../../commit/fff32c2))
20
+ * change query params for matrix to use pacticipant[]=? and version[]=? ([003e305](/../../commit/003e305))
21
+
22
+
23
+ #### Bug Fixes
24
+
25
+ * **can-i-deploy**
26
+ * correct provider name in text output ([bfd0882](/../../commit/bfd0882))
27
+
28
+
1
29
  <a name="v1.8.0"></a>
2
30
  ### v1.8.0 (2017-10-19)
3
31
 
data/RELEASING.md CHANGED
@@ -1,16 +1,5 @@
1
1
  # Releasing
2
2
 
3
- 1. Increment the version in `lib/pact_broker/client/version.rb`
4
- 2. `bundle exec appraisal update`
5
- 3. Update the `CHANGELOG.md` using:
6
-
7
- $ bundle exec rake generate_changelog
8
-
9
- 4. Add files to git
10
-
11
- $ git add CHANGELOG.md lib/pact_broker/client/version.rb gemfiles
12
- $ git commit -m "Releasing version $(ruby -r ./lib/pact_broker/client/version.rb -e "puts PactBroker::Client::VERSION")"
13
-
14
- 5. Release:
15
-
16
- $ bundle exec rake release
3
+ 1. Check status of https://travis-ci.org/pact-foundation/pact_broker-client
4
+ 2. Increment the version in `lib/pact_broker/client/version.rb`
5
+ 3. Run script/release.sh
data/Rakefile CHANGED
@@ -12,7 +12,12 @@ RSpec::Core::RakeTask.new('spec:providers') do | task |
12
12
  task.rspec_opts = "--pattern spec/service_providers/**/*_spec.rb"
13
13
  end
14
14
 
15
- task :default => [:spec, 'spec:providers']
15
+ # Must be run after spec:providers because it relies on the generated pact
16
+ RSpec::Core::RakeTask.new('spec:integration') do | task |
17
+ task.rspec_opts = "--pattern spec/integration/**/*_spec.rb"
18
+ end
19
+
20
+ task :default => [:spec, 'spec:providers', 'spec:integration']
16
21
 
17
22
  task :generate_changelog do
18
23
  require 'pact_broker/client/version'
@@ -1,6 +1,7 @@
1
1
  require 'erb'
2
2
  require 'httparty'
3
3
  require 'pact_broker/client/error'
4
+ require 'cgi'
4
5
 
5
6
  module PactBroker
6
7
  module Client
@@ -11,6 +12,10 @@ module PactBroker
11
12
  def encode_param param
12
13
  ERB::Util.url_encode param
13
14
  end
15
+
16
+ def encode_query_param param
17
+ CGI::escape param
18
+ end
14
19
  end
15
20
 
16
21
  module StringToSymbol
@@ -65,7 +70,14 @@ module PactBroker
65
70
  else
66
71
  error_message = nil
67
72
  begin
68
- error_message = JSON.parse(response.body)['errors'].join("\n")
73
+ errors = JSON.parse(response.body)['errors']
74
+ error_message = if errors.is_a?(Array)
75
+ errors.join("\n")
76
+ elsif errors.is_a?(Hash)
77
+ errors.collect{ |key, value| "#{key}: #{value}" }.join("\n")
78
+ else
79
+ response.body
80
+ end
69
81
  rescue
70
82
  raise Error.new(response.body)
71
83
  end
@@ -3,7 +3,6 @@ require 'pact_broker/client/pact_broker_client'
3
3
  require 'pact_broker/client/retry'
4
4
  require 'pact_broker/client/matrix/formatter'
5
5
 
6
-
7
6
  module PactBroker
8
7
  module Client
9
8
  class CanIDeploy
@@ -45,7 +44,7 @@ module PactBroker
45
44
  attr_reader :pact_broker_base_url, :version_selectors, :options, :pact_broker_client_options
46
45
 
47
46
  def success_message(matrix)
48
- message = format_matrix(matrix[:matrix])
47
+ message = format_matrix(matrix)
49
48
  if format != 'json'
50
49
  message = 'Computer says yes \o/' + "\n\n" + message
51
50
  end
@@ -53,7 +52,7 @@ module PactBroker
53
52
  end
54
53
 
55
54
  def failure_message(matrix)
56
- message = format_matrix(matrix[:matrix])
55
+ message = format_matrix(matrix)
57
56
  if format != 'json'
58
57
  message = 'Computer says no ¯\_(ツ)_/¯' + "\n\n" + message
59
58
  end
@@ -1,9 +1,11 @@
1
- require 'pact_broker/client/can_i_deploy'
2
1
  require 'pact_broker/client/version'
2
+ require 'pact_broker/client/can_i_deploy'
3
+ require 'pact_broker/client/git'
3
4
  require 'pact_broker/client/cli/version_selector_options_parser'
4
5
  require 'pact_broker/client/cli/custom_thor'
5
6
  require 'pact_broker/client/publish_pacts'
6
7
  require 'rake/file_list'
8
+ require 'thor/error'
7
9
 
8
10
  module PactBroker
9
11
  module Client
@@ -14,16 +16,17 @@ module PactBroker
14
16
  class Broker < CustomThor
15
17
  desc 'can-i-deploy', "Returns exit code 0 or 1, indicating whether or not the specified application versions are compatible."
16
18
 
17
- method_option :name, required: true, aliases: "-n", desc: "The application name. Use once for each pacticipant being checked."
18
- method_option :version, required: true, aliases: "-a", desc: "The application version. Must be entered after a --name."
19
+ method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
20
+ method_option :version, required: true, aliases: "-e", desc: "The application version. Must be entered after the --pacticipant that it relates to."
19
21
  method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
20
22
  method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
21
23
  method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
22
24
  method_option :output, aliases: "-o", desc: "json or table", default: 'table'
23
- method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false
25
+ method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
24
26
 
25
- def can_i_deploy
27
+ def can_i_deploy(*ignored_but_necessary)
26
28
  selectors = VersionSelectorOptionsParser.call(ARGV)
29
+ validate_can_i_deploy_selectors(selectors)
27
30
  result = CanIDeploy.call(options.broker_base_url, selectors, {output: options.output}, pact_broker_client_options)
28
31
  $stdout.puts result.message
29
32
  exit(1) unless result.success
@@ -35,7 +38,8 @@ module PactBroker
35
38
  method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
36
39
  method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
37
40
  method_option :tag, aliases: "-t", type: :array, banner: "TAG", desc: "Tag name for consumer version. Can be specified multiple times."
38
- method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false
41
+ method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag consumer version with the name of the current git branch. Default: false"
42
+ method_option :verbose, aliases: "-v", type: :boolean, default: false, required: false, desc: "Verbose output. Default: false"
39
43
 
40
44
  def publish(*pact_files)
41
45
  validate_pact_files(pact_files)
@@ -58,10 +62,15 @@ module PactBroker
58
62
 
59
63
  def validate_pact_files pact_files
60
64
  unless pact_files && pact_files.any?
61
- raise RequiredArgumentMissingError, "No value provided for required pact_files"
65
+ raise ::Thor::RequiredArgumentMissingError, "No value provided for required pact_files"
62
66
  end
63
67
  end
64
68
 
69
+ def validate_can_i_deploy_selectors selectors
70
+ pacticipants_without_versions = selectors.select{ |s| s[:version].nil? }.collect{ |s| s[:pacticipant] }
71
+ raise ::Thor::RequiredArgumentMissingError, "No --version provided for pacticipant #{pacticipants_without_versions.join(", ")}" if pacticipants_without_versions.any?
72
+ end
73
+
65
74
  def publish_pacts pact_files
66
75
  PactBroker::Client::PublishPacts.call(
67
76
  options.broker_base_url,
@@ -83,7 +92,9 @@ module PactBroker
83
92
  end
84
93
 
85
94
  def tags
86
- [*options.tag].compact
95
+ t = [*options.tag]
96
+ t << PactBroker::Client::Git.branch if options.tag_with_git_branch
97
+ t.compact.uniq
87
98
  end
88
99
 
89
100
  def pact_broker_client_options
@@ -7,15 +7,16 @@ module PactBroker
7
7
  last_flag = nil
8
8
  options.each do | option |
9
9
  case option
10
- when "--name", "-n"
10
+ when "--pacticipant", "-a"
11
11
  versions << {}
12
12
  when /^\-/
13
13
  nil
14
14
  else
15
15
  case last_flag
16
- when "--name", "-n"
17
- versions.last[:name] = option
18
- when "--version", "-a"
16
+ when "--pacticipant", "-a"
17
+ versions.last[:pacticipant] = option
18
+ when "--version", "-e"
19
+ versions << {pacticipant: nil} unless versions.last
19
20
  versions.last[:version] = option
20
21
  end
21
22
  end
@@ -0,0 +1,15 @@
1
+ require 'pact_broker/client/error'
2
+
3
+ module PactBroker
4
+ module Client
5
+ module Git
6
+ COMMAND = 'git rev-parse --abbrev-ref HEAD'
7
+
8
+ def self.branch
9
+ `#{COMMAND}`.strip
10
+ rescue StandardError => e
11
+ raise PactBroker::Client::Error, "Could not determine current git branch using command `#{COMMAND}`. #{e.class} #{e.message}"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,8 +3,10 @@ require_relative 'base_client'
3
3
  module PactBroker
4
4
  module Client
5
5
  class Matrix < BaseClient
6
- def get selectors
7
- query = {selectors: convert_selector_hashes_to_params(selectors)}
6
+ def get selectors, options = {}
7
+ query = {
8
+ q: convert_selector_hashes_to_params(selectors)
9
+ }.merge(query_options(options))
8
10
  response = self.class.get("/matrix", query: query, headers: default_get_headers)
9
11
  $stdout.puts("DEBUG: Response headers #{response.headers}") if verbose?
10
12
  $stdout.puts("DEBUG: Response body #{response}") if verbose?
@@ -31,8 +33,20 @@ module PactBroker
31
33
  end
32
34
  end
33
35
 
36
+ def query_options(options)
37
+ opts = {}
38
+ if options.key?(:success)
39
+ opts[:success] = [*options[:success]]
40
+ end
41
+ opts
42
+ end
43
+
34
44
  def convert_selector_hashes_to_params(selectors)
35
- selectors.collect{ |selector| "#{selector[:name]}/version/#{selector[:version]}" }
45
+ selectors.collect do |selector|
46
+ { pacticipant: selector[:pacticipant] }.tap do | hash |
47
+ hash[:version] = selector[:version] if selector[:version]
48
+ end
49
+ end
36
50
  end
37
51
  end
38
52
  end
@@ -4,8 +4,8 @@ module PactBroker
4
4
  module Client
5
5
  class Matrix
6
6
  class JsonFormatter
7
- def self.call(matrix_lines)
8
- JSON.pretty_generate(matrix: matrix_lines)
7
+ def self.call(matrix)
8
+ JSON.pretty_generate(matrix)
9
9
  end
10
10
  end
11
11
  end
@@ -7,12 +7,12 @@ module PactBroker
7
7
 
8
8
  Line = Struct.new(:consumer, :consumer_version, :provider, :provider_version, :success)
9
9
 
10
- def self.call(matrix_lines)
11
- data = matrix_lines.collect do | line |
10
+ def self.call(matrix)
11
+ data = matrix[:matrix].collect do | line |
12
12
  Line.new(
13
13
  lookup(line, :consumer, :name),
14
14
  lookup(line, :consumer, :version, :number),
15
- lookup(line, :consumer, :name),
15
+ lookup(line, :provider, :name),
16
16
  lookup(line, :provider, :version, :number),
17
17
  lookup(line, :verificationResult, :success).to_s
18
18
  )
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '1.8.0'
3
+ VERSION = '1.9.0'
4
4
  end
5
5
  end
@@ -7,9 +7,9 @@ require 'pact_broker/client/version'
7
7
  Gem::Specification.new do |gem|
8
8
  gem.name = "pact_broker-client"
9
9
  gem.version = PactBroker::Client::VERSION
10
- gem.authors = ["Bethany Skurrie"]
10
+ gem.authors = ["Beth Skurrie"]
11
11
  gem.email = ["bskurrie@dius.com.au"]
12
- gem.description = %q{Publishes pacts to, and retrieves pacts from, the pact broker server.}
12
+ gem.description = %q{Client for the Pact Broker. Publish, retrieve and query pacts and verification results.}
13
13
  gem.summary = %q{See description}
14
14
  gem.homepage = "https://github.com/bethesque/pact_broker-client.git"
15
15
 
@@ -27,7 +27,6 @@ Gem::Specification.new do |gem|
27
27
  gem.add_runtime_dependency 'table_print', '~> 1.5'
28
28
 
29
29
  gem.add_development_dependency 'fakefs', '~> 0.4'
30
- gem.add_development_dependency 'appraisal'
31
30
  gem.add_development_dependency 'webmock', '~> 3.0'
32
31
  gem.add_development_dependency 'conventional-changelog'
33
32
  gem.add_development_dependency 'pact', '~> 1.16'
@@ -0,0 +1 @@
1
+ bundle exec bin/pact-broker publish spec/pacts/pact_broker_client-pact_broker.json --consumer-app-version 1.2.3 --broker-base-url http://localhost:9292 --tag-with-git-branch
data/script/release.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -e
3
+ bundle exec rake
4
+ bundle exec rake generate_changelog
5
+ git add CHANGELOG.md lib/pact_broker/client/version.rb
6
+ git commit -m "Releasing version $(ruby -r ./lib/pact_broker/client/version.rb -e "puts PactBroker::Client::VERSION")"
7
+ bundle exec rake release
@@ -0,0 +1,32 @@
1
+ describe "pact-broker can-i-deploy" do
2
+ before(:all) do
3
+ @pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5000")
4
+ sleep 2
5
+ end
6
+
7
+ context "when the pacticipants can be deployed" do
8
+ subject { `bundle exec bin/pact-broker can-i-deploy -v --pacticipant Foo --version 1.2.3 --pacticipant Bar --version 4.5.6 --broker-base-url http://localhost:5000` }
9
+
10
+ it "returns a success exit code" do
11
+ subject
12
+ expect($?.exitstatus).to eq 0
13
+ expect(subject).to match /CONSUMER/
14
+ expect(subject).to match /Foo/
15
+ expect(subject).to match /PROVIDER/
16
+ expect(subject).to match /Bar/
17
+ end
18
+ end
19
+
20
+ context "when the pacticipants can't be deployed" do
21
+ subject { `bundle exec bin/pact-broker can-i-deploy -v --pacticipant Wiffle --version 1.2.3 --pacticipant Meep --version 4.5.6 --broker-base-url http://localhost:5000` }
22
+
23
+ it "returns an error exit code" do
24
+ subject
25
+ expect($?.exitstatus).to_not eq 0
26
+ end
27
+ end
28
+
29
+ after(:all) do
30
+ Process.kill 'KILL', @pipe.pid
31
+ end
32
+ end
@@ -4,7 +4,7 @@ module PactBroker
4
4
  module Client
5
5
  describe CanIDeploy do
6
6
  let(:pact_broker_base_url) { 'http://example.org' }
7
- let(:version_selectors) { [{name: "Foo", version: "1"}] }
7
+ let(:version_selectors) { [{pacticipant: "Foo", version: "1"}] }
8
8
  let(:pact_broker_client_options) { { foo: 'bar' } }
9
9
  let(:matrix_client) { instance_double('PactBroker::Client::Matrix') }
10
10
  let(:matrix) { {matrix: ['foo'], summary: {compatible: true}} }
@@ -24,7 +24,7 @@ module PactBroker
24
24
  end
25
25
 
26
26
  it "creates a text table out of the matrix" do
27
- expect(Matrix::Formatter).to receive(:call).with(['foo'], 'text')
27
+ expect(Matrix::Formatter).to receive(:call).with(matrix, 'text')
28
28
  subject
29
29
  end
30
30
 
@@ -15,7 +15,7 @@ module PactBroker
15
15
  let(:result) { instance_double('PactBroker::Client::CanIDeploy::Result', success: success, message: message) }
16
16
  let(:success) { true }
17
17
  let(:message) { 'message' }
18
- let(:version_selectors) { ['selector1'] }
18
+ let(:version_selectors) { [{pacticipant: "Foo", version: "1"}] }
19
19
  let(:minimum_valid_options) do
20
20
  {
21
21
  broker_base_url: 'http://pact-broker',
@@ -36,6 +36,14 @@ module PactBroker
36
36
  invoke_can_i_deploy
37
37
  end
38
38
 
39
+ context "with a missing --version" do
40
+ let(:version_selectors) { [{pacticipant: "Foo", version: nil}] }
41
+
42
+ it "raises an error" do
43
+ expect { invoke_can_i_deploy }.to raise_error Thor::RequiredArgumentMissingError, "No --version provided for pacticipant Foo"
44
+ end
45
+ end
46
+
39
47
  context "with basic auth" do
40
48
  before do
41
49
  subject.options = OpenStruct.new(minimum_valid_options.merge(broker_username: 'foo', broker_password: 'bar'))