Skip to content

Commit

Permalink
chore(http test data builder): add method to verify using old API [ci…
Browse files Browse the repository at this point in the history
…-skip]
  • Loading branch information
bethesque committed Jan 29, 2021
1 parent f14e9a3 commit 1af12be
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions lib/pact_broker/test/http_test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,22 @@ def print_pacts_for_verification
self
end

def verify_latest_pact_for_tag(success: true, provider: last_provider_name, consumer: last_consumer_name, consumer_version_tag: , provider_version:, provider_version_tag: nil)
@last_provider_name = provider
@last_consumer_name = consumer
url_of_pact_to_verify = "pacts/provider/#{encode(provider)}/consumer/#{encode(consumer)}/latest/#{encode(consumer_version_tag)}"
publish_verification_results(url_of_pact_to_verify, provider, provider_version, provider_version_tag, success)
separate
self
end

def verify_pact(index: 0, success:, provider: last_provider_name, provider_version_tag: , provider_version: )
@last_provider_name = provider
pact_to_verify = @pacts_for_verification_response.body["_embedded"]["pacts"][index]
raise "No pact found to verify at index #{index}" unless pact_to_verify
url_of_pact_to_verify = pact_to_verify["_links"]["self"]["href"]

[*provider_version_tag].each do | tag |
create_tag(pacticipant: provider, version: provider_version, tag: tag)
end
puts "" if [*provider_version_tag].any?

pact_response = client.get(url_of_pact_to_verify).tap { |response| check_for_error(response) }
verification_results_url = pact_response.body["_links"]["pb:publish-verification-results"]["href"]

results = {
success: success,
testResults: [],
providerApplicationVersion: provider_version
}
puts "Publishing verification"
puts results.to_yaml
response = client.post(verification_results_url, results.to_json).tap { |response| check_for_error(response) }
publish_verification_results(url_of_pact_to_verify, provider, provider_version, provider_version_tag, success)
separate
self
end
Expand Down Expand Up @@ -250,6 +244,27 @@ def generate_content(consumer_name, provider_name, content_id)
}
end

private

def publish_verification_results(url_of_pact_to_verify, provider, provider_version, provider_version_tag, success)
[*provider_version_tag].each do | tag |
create_tag(pacticipant: provider, version: provider_version, tag: tag)
end
puts "" if [*provider_version_tag].any?

pact_response = client.get(url_of_pact_to_verify).tap { |response| check_for_error(response) }
verification_results_url = pact_response.body["_links"]["pb:publish-verification-results"]["href"]

results = {
success: success,
testResults: [],
providerApplicationVersion: provider_version
}
puts "Publishing verification"
puts results.to_yaml
response = client.post(verification_results_url, results.to_json).tap { |response| check_for_error(response) }
end

def encode string
ERB::Util.url_encode(string)
end
Expand Down

0 comments on commit 1af12be

Please sign in to comment.