Skip to content

Commit

Permalink
feat(can-i-deploy): change --name to --pacticipant
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 28, 2017
1 parent c09bba2 commit d5d23bc
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 207 deletions.
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ RSpec::Core::RakeTask.new('spec:providers') do | task |
task.rspec_opts = "--pattern spec/service_providers/**/*_spec.rb"
end

task :default => [:spec, 'spec:providers']
# Must be run after spec:providers because it relies on the generated pact
RSpec::Core::RakeTask.new('spec:integration') do | task |
task.rspec_opts = "--pattern spec/integration/**/*_spec.rb"
end

task :default => [:spec, 'spec:providers', 'spec:integration']

task :generate_changelog do
require 'pact_broker/client/version'
Expand Down
6 changes: 3 additions & 3 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class PactPublicationError < ::Thor::Error; end
class Broker < CustomThor
desc 'can-i-deploy', "Returns exit code 0 or 1, indicating whether or not the specified application versions are compatible."

method_option :name, required: true, aliases: "-n", desc: "The application name. Use once for each pacticipant being checked."
method_option :version, required: true, aliases: "-a", desc: "The application version. Must be entered after a --name."
method_option :pacticipant, required: true, aliases: "-a", desc: "The pacticipant name. Use once for each pacticipant being checked."
method_option :version, required: true, aliases: "-e", desc: "The application version. Must be entered after the --pacticipant that it relates to."
method_option :broker_base_url, required: true, aliases: "-b", desc: "The base URL of the Pact Broker"
method_option :broker_username, aliases: "-u", desc: "Pact Broker basic auth username"
method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password"
method_option :output, aliases: "-o", desc: "json or table", default: 'table'
method_option :verbose, aliases: "-v", desc: "Verbose output", :required => false

def can_i_deploy(*ignored)
def can_i_deploy(*ignored_but_necessary)
selectors = VersionSelectorOptionsParser.call(ARGV)
result = CanIDeploy.call(options.broker_base_url, selectors, {output: options.output}, pact_broker_client_options)
$stdout.puts result.message
Expand Down
9 changes: 5 additions & 4 deletions lib/pact_broker/client/cli/version_selector_options_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ def self.call options
last_flag = nil
options.each do | option |
case option
when "--name", "-n"
when "--pacticipant", "-a"
versions << {}
when /^\-/
nil
else
case last_flag
when "--name", "-n"
versions.last[:name] = option
when "--version", "-a"
when "--pacticipant", "-a"
versions.last[:pacticipant] = option
when "--version", "-e"
versions << {pacticipant: nil} unless versions.last
versions.last[:version] = option
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/client/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def handle_response response
end

def convert_selector_hashes_to_params(selectors)
selectors.collect{ |selector| {pacticipant: selector[:name], version: selector[:version]} }
selectors.collect{ |selector| {pacticipant: selector[:pacticipant], version: selector[:version]} }
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/integration/can_i_deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe "pact-broker can-i-deploy" do
before(:all) do
@pipe = IO.popen("bundle exec pact-stub-service spec/pacts/pact_broker_client-pact_broker.json -p 5000")
sleep 2
end

context "when the pacticipants can be deployed" do
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` }

it "returns a success exit code" do
subject
expect($?.exitstatus).to eq 0
expect(subject).to match /CONSUMER/
expect(subject).to match /Foo/
expect(subject).to match /PROVIDER/
expect(subject).to match /Bar/
end
end

context "when the pacticipants can't be deployed" do
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` }

it "returns an error exit code" do
subject
expect($?.exitstatus).to_not eq 0
end
end

after(:all) do
Process.kill 'KILL', @pipe.pid
end
end
4 changes: 2 additions & 2 deletions spec/lib/pact_broker/client/can_i_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module PactBroker
module Client
describe CanIDeploy do
let(:pact_broker_base_url) { 'http://example.org' }
let(:version_selectors) { [{name: "Foo", version: "1"}] }
let(:version_selectors) { [{pacticipant: "Foo", version: "1"}] }
let(:pact_broker_client_options) { { foo: 'bar' } }
let(:matrix_client) { instance_double('PactBroker::Client::Matrix') }
let(:matrix) { {matrix: ['foo'], summary: {compatible: true}} }
Expand All @@ -24,7 +24,7 @@ module Client
end

it "creates a text table out of the matrix" do
expect(Matrix::Formatter).to receive(:call).with(['foo'], 'text')
expect(Matrix::Formatter).to receive(:call).with(matrix, 'text')
subject
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ module CLI

TEST_CASES = [
[
["--name", "Foo", "--version", "1.2.3"],
[{ name: "Foo", version: "1.2.3" } ]
["--pacticipant", "Foo", "--version", "1.2.3"],
[{ pacticipant: "Foo", version: "1.2.3" } ]
],[
["-n", "Foo", "-a", "1.2.3"],
[{ name: "Foo", version: "1.2.3" } ]
["-a", "Foo", "-e", "1.2.3"],
[{ pacticipant: "Foo", version: "1.2.3" } ]
],[
["--name", "Foo"],
[{ name: "Foo" } ]
["--pacticipant", "Foo"],
[{ pacticipant: "Foo" } ]
],[
["--name", "Foo", "Bar"],
[{ name: "Bar" } ]
["--pacticipant", "Foo", "Bar"],
[{ pacticipant: "Bar" } ]
],[
["--name", "Foo", "--name", "Bar", "--version", "1.2.3"],
[{ name: "Foo" }, { name: "Bar", version: "1.2.3" } ]
["--pacticipant", "Foo", "--pacticipant", "Bar", "--version", "1.2.3"],
[{ pacticipant: "Foo" }, { pacticipant: "Bar", version: "1.2.3" } ]
],[
["--name", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
[{ name: "Foo", version: "1.2.3" } ]
["--pacticipant", "Foo", "--wrong", "Bar", "--version", "1.2.3"],
[{ pacticipant: "Foo", version: "1.2.3" } ]
],[
["--name", "the-thing", "--version", "1.2.3"],
[{ name: "the-thing", version: "1.2.3" } ]
["--pacticipant", "the-thing", "--version", "1.2.3"],
[{ pacticipant: "the-thing", version: "1.2.3" } ]
],[
["--version", "1.2.3"],
[{ pacticipant: nil, version: "1.2.3" } ]
]
]

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/client/matrix/text_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module PactBroker
module Client
describe Matrix::TextFormatter do
let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true) }
let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix] }
let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }

# SublimeText removes whitespace from the end of files when you save them,
Expand Down
Loading

0 comments on commit d5d23bc

Please sign in to comment.