Skip to content

Commit

Permalink
feat: provide configuration for build url to be published in verifica…
Browse files Browse the repository at this point in the history
…tion results (#252)
  • Loading branch information
konalegi authored Feb 24, 2022
1 parent 0dc6371 commit ce1c9bc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 16 deletions.
5 changes: 3 additions & 2 deletions lib/pact/provider/configuration/service_provider_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ module Configuration
class ServiceProviderConfig

attr_accessor :application_version
attr_reader :branch
attr_reader :branch, :build_url

def initialize application_version, branch, tags, publish_verification_results, &app_block
def initialize application_version, branch, tags, publish_verification_results, build_url, &app_block
@application_version = application_version
@branch = branch
@tags = [*tags]
@publish_verification_results = publish_verification_results
@app_block = app_block
@build_url = build_url
end

def app
Expand Down
8 changes: 6 additions & 2 deletions lib/pact/provider/configuration/service_provider_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServiceProviderDSL

extend Pact::DSL

attr_accessor :name, :app_block, :application_version, :branch, :tags, :publish_verification_results
attr_accessor :name, :app_block, :application_version, :branch, :tags, :publish_verification_results, :build_url

CONFIG_RU_APP = lambda {
unless File.exist? Pact.configuration.config_ru_path
Expand Down Expand Up @@ -48,6 +48,10 @@ def app_version_branch branch
self.branch = branch
end

def build_url build_url
self.build_url = build_url
end

def publish_verification_results publish_verification_results
self.publish_verification_results = publish_verification_results
Pact::RSpec.with_rspec_2 do
Expand Down Expand Up @@ -89,7 +93,7 @@ def application_version_blank?
end

def create_service_provider
Pact.configuration.provider = ServiceProviderConfig.new(application_version, branch, tags, publish_verification_results, &@app_block)
Pact.configuration.provider = ServiceProviderConfig.new(application_version, branch, tags, publish_verification_results, build_url, &@app_block)
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/pact/provider/verification_results/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def initialize pact_source, test_results_hash
end

def call
VerificationResult.new(publishable?, !any_failures?, Pact.configuration.provider.application_version, test_results_hash_for_pact_uri)
VerificationResult.new(
publishable?,
!any_failures?,
Pact.configuration.provider.application_version,
test_results_hash_for_pact_uri,
Pact.configuration.provider.build_url
)
end

private
Expand Down
6 changes: 4 additions & 2 deletions lib/pact/provider/verification_results/verification_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module VerificationResults
class VerificationResult
attr_reader :success, :provider_application_version, :test_results_hash

def initialize publishable, success, provider_application_version, test_results_hash
def initialize publishable, success, provider_application_version, test_results_hash, build_url
@publishable = publishable
@success = success
@provider_application_version = provider_application_version
@test_results_hash = test_results_hash
@build_url = build_url
end

def publishable?
Expand All @@ -25,7 +26,8 @@ def to_json(options = {})
{
success: success,
providerApplicationVersion: provider_application_version,
testResults: test_results_hash
testResults: test_results_hash,
buildUrl: @build_url
}.to_json(options)
end

Expand Down
3 changes: 2 additions & 1 deletion spec/integration/publish_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
application_version: '1.2.3',
publish_verification_results?: true,
branch: nil,
tags: [])
tags: [],
build_url: 'http://ci/build/1')
end

let(:pact_sources) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Configuration

let(:app_block) { ->{ Object.new } }

subject { ServiceProviderConfig.new("1.2.3'", "main", [], true, &app_block) }
subject { ServiceProviderConfig.new("1.2.3'", "main", [], true, 'http://ci/build/1', &app_block) }

it "should execute the app_block each time" do
expect(subject.app.object_id).to_not equal(subject.app.object_id)
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/pact/provider/configuration/service_provider_dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ module Configuration
end
end

context 'with build_url' do
subject(:config_build_url) { Pact.configuration.provider.build_url }
let(:ci_build_url) { 'http://ci/build/1' }

before do
ServiceProviderDSL.build 'name' do
build_url ci_build_url
end
end

it { is_expected.to eq(ci_build_url) }
end

end

describe "validate" do
Expand Down
21 changes: 14 additions & 7 deletions spec/lib/pact/provider/verification_results/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ module VerificationResults

let(:verification_result) { double('VerificationResult') }
let(:provider_configuration) do
double('provider_configuration', application_version: '1.2.3')
double('provider_configuration', application_version: '1.2.3', build_url: ci_build)
end
let(:ci_build) { 'http://ci/build/1' }
let(:pact_source_1) do
instance_double('Pact::Provider::PactSource', uri: pact_uri_1, consumer_contract: consumer_contract)
end
Expand Down Expand Up @@ -59,19 +60,25 @@ module VerificationResults
}
}
}
expect(VerificationResult).to receive(:new).with(anything, anything, anything, expected_test_results_hash)
expect(VerificationResult).to receive(:new).with(anything, anything, anything, expected_test_results_hash, anything)
subject
end

it "creates a VerificationResult with the provider application version" do
expect(provider_configuration).to receive(:application_version)
expect(VerificationResult).to receive(:new).with(anything, anything, '1.2.3', anything)
expect(VerificationResult).to receive(:new).with(anything, anything, '1.2.3', anything, anything)
subject
end

it "creates a VerificationResult with the provider ci build url" do
expect(provider_configuration).to receive(:build_url)
expect(VerificationResult).to receive(:new).with(anything, anything, anything, anything, ci_build)
subject
end

context "when every interaction has been executed" do
it "sets publishable to true" do
expect(VerificationResult).to receive(:new).with(true, anything, anything, anything)
expect(VerificationResult).to receive(:new).with(true, anything, anything, anything, anything)
subject
end
end
Expand All @@ -81,14 +88,14 @@ module VerificationResults
let(:interactions) { [interaction_1, interaction_2]}

it "sets publishable to false" do
expect(VerificationResult).to receive(:new).with(false, anything, anything, anything)
expect(VerificationResult).to receive(:new).with(false, anything, anything, anything, anything)
subject
end
end

context "when all the examples passed" do
it "sets the success to true" do
expect(VerificationResult).to receive(:new).with(anything, true, anything, anything)
expect(VerificationResult).to receive(:new).with(anything, true, anything, anything, anything)
subject
end
end
Expand All @@ -99,7 +106,7 @@ module VerificationResults
end

it "sets the success to false" do
expect(VerificationResult).to receive(:new).with(anything, false, anything, anything)
expect(VerificationResult).to receive(:new).with(anything, false, anything, anything, anything)
subject
end

Expand Down

0 comments on commit ce1c9bc

Please sign in to comment.