pact 1.27.0 → 1.28.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pact/hal/entity.rb +8 -0
- data/lib/pact/hal/http_client.rb +11 -4
- data/lib/pact/hal/link.rb +1 -1
- data/lib/pact/pact_broker/fetch_pacts.rb +55 -43
- data/lib/pact/provider/configuration/pact_verification_from_broker.rb +57 -0
- data/lib/pact/provider/configuration/service_provider_dsl.rb +9 -0
- data/lib/pact/provider/pact_verification.rb +14 -14
- data/lib/pact/provider/world.rb +16 -2
- data/lib/pact/version.rb +1 -1
- data/pact.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab681c832d6b149fbb741fe2e371104213de90ba
|
4
|
+
data.tar.gz: b4d6d007778f40bca100d30487405a763169bec2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47aeced718b4ba58d79f0398daffd9ddd7fedd6202638b396c7c989014af6af886e8e0e41acef3cf60c3ec86b1c7d1c57bdadce47499c12a595d8bbae1802f76
|
7
|
+
data.tar.gz: 3cbef7b20bb39ee771b4ecb393cb344415be862952b115c867c1e24356701f870c1e1ffe6faa7f744c4ae02dd5e6ae2a4d62b7ec20cc016f23341e4277044e17
|
data/lib/pact/hal/entity.rb
CHANGED
data/lib/pact/hal/http_client.rb
CHANGED
@@ -3,11 +3,12 @@ require 'pact/retry'
|
|
3
3
|
module Pact
|
4
4
|
module Hal
|
5
5
|
class HttpClient
|
6
|
-
attr_accessor :username, :password
|
6
|
+
attr_accessor :username, :password, :verbose
|
7
7
|
|
8
8
|
def initialize options
|
9
9
|
@username = options[:username]
|
10
10
|
@password = options[:password]
|
11
|
+
@verbose = options[:verbose]
|
11
12
|
end
|
12
13
|
|
13
14
|
def get href, params = {}, headers = {}
|
@@ -41,9 +42,11 @@ module Pact
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def perform_request request, uri
|
44
|
-
options = {:use_ssl => uri.scheme == 'https'}
|
45
45
|
response = Retry.until_true do
|
46
|
-
Net::HTTP.
|
46
|
+
http = Net::HTTP.new(uri.host, uri.port, :ENV)
|
47
|
+
http.set_debug_output(Pact.configuration.output_stream) if verbose
|
48
|
+
http.use_ssl = (uri.scheme == 'https')
|
49
|
+
http.start do |http|
|
47
50
|
http.request request
|
48
51
|
end
|
49
52
|
end
|
@@ -52,7 +55,7 @@ module Pact
|
|
52
55
|
|
53
56
|
class Response < SimpleDelegator
|
54
57
|
def body
|
55
|
-
bod =
|
58
|
+
bod = raw_body
|
56
59
|
if bod && bod != ''
|
57
60
|
JSON.parse(bod)
|
58
61
|
else
|
@@ -60,6 +63,10 @@ module Pact
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
66
|
+
def raw_body
|
67
|
+
__getobj__().body
|
68
|
+
end
|
69
|
+
|
63
70
|
def success?
|
64
71
|
__getobj__().code.start_with?("2")
|
65
72
|
end
|
data/lib/pact/hal/link.rb
CHANGED
@@ -49,7 +49,7 @@ module Pact
|
|
49
49
|
if http_response.success?
|
50
50
|
Entity.new(http_response.body, @http_client, http_response)
|
51
51
|
else
|
52
|
-
ErrorEntity.new(http_response.
|
52
|
+
ErrorEntity.new(http_response.raw_body, @http_client, http_response)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -1,74 +1,76 @@
|
|
1
1
|
require 'pact/hal/entity'
|
2
2
|
require 'pact/hal/http_client'
|
3
|
+
require 'pact/provider/pact_uri'
|
3
4
|
|
4
5
|
module Pact
|
5
6
|
module PactBroker
|
6
7
|
class FetchPacts
|
7
|
-
attr_reader :provider, :tags, :broker_base_url, :
|
8
|
+
attr_reader :provider, :tags, :broker_base_url, :http_client_options, :http_client, :index_entity
|
8
9
|
|
9
10
|
ALL_PROVIDER_TAG_RELATION = 'pb:provider-pacts-with-tag'.freeze
|
10
11
|
LATEST_PROVIDER_TAG_RELATION = 'pb:latest-provider-pacts-with-tag'.freeze
|
11
|
-
ALL_PROVIDER_RELATION = 'pb:provider-pacts'.freeze
|
12
12
|
LATEST_PROVIDER_RELATION = 'pb:latest-provider-pacts'.freeze
|
13
13
|
PACTS = 'pacts'.freeze
|
14
14
|
HREF = 'href'.freeze
|
15
15
|
|
16
|
-
def initialize(provider, tags, broker_base_url,
|
16
|
+
def initialize(provider, tags, broker_base_url, http_client_options)
|
17
17
|
@provider = provider
|
18
|
-
@tags = tags
|
18
|
+
@tags = (tags || []).collect do |tag|
|
19
|
+
if tag.is_a?(String)
|
20
|
+
{ name: tag, all: false, fallback: nil }
|
21
|
+
else
|
22
|
+
tag
|
23
|
+
end
|
24
|
+
end
|
25
|
+
@http_client_options = http_client_options
|
19
26
|
@broker_base_url = broker_base_url
|
20
|
-
@http_client = Pact::Hal::HttpClient.new(
|
21
|
-
@all_pacts = all_pacts
|
27
|
+
@http_client = Pact::Hal::HttpClient.new(http_client_options)
|
22
28
|
end
|
23
29
|
|
24
|
-
def self.call(provider, tags, broker_base_url,
|
25
|
-
new(provider, tags, broker_base_url,
|
30
|
+
def self.call(provider, tags, broker_base_url, http_client_options)
|
31
|
+
new(provider, tags, broker_base_url, http_client_options).call
|
26
32
|
end
|
27
33
|
|
28
34
|
def call
|
29
|
-
|
30
|
-
if
|
31
|
-
|
35
|
+
log_message
|
36
|
+
if get_index.success?
|
37
|
+
if any_tags?
|
38
|
+
get_tagged_pacts_for_provider
|
39
|
+
else
|
40
|
+
get_latest_pacts_for_provider
|
41
|
+
end
|
32
42
|
else
|
33
|
-
|
43
|
+
raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
37
47
|
private
|
38
48
|
|
39
|
-
def
|
40
|
-
|
41
|
-
get_all_pacts_for_provider
|
42
|
-
else
|
43
|
-
get_latest_pacts_for_provider
|
44
|
-
end
|
49
|
+
def any_tags?
|
50
|
+
tags && tags.any?
|
45
51
|
end
|
46
52
|
|
47
53
|
def get_tagged_pacts_for_provider
|
48
|
-
|
49
|
-
|
54
|
+
tags.collect do |tag|
|
55
|
+
link = get_link(tag)
|
56
|
+
urls = get_pact_urls(link.expand(provider: provider, tag: tag[:name]).get)
|
57
|
+
if urls == [] && tag[:fallback]
|
58
|
+
urls = get_pact_urls(link.expand(provider: provider, tag: tag[:fallback]).get)
|
59
|
+
end
|
60
|
+
urls
|
61
|
+
end.flatten
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_link(tag)
|
65
|
+
if !tag[:all]
|
66
|
+
index_entity._link(LATEST_PROVIDER_TAG_RELATION)
|
50
67
|
else
|
51
|
-
|
68
|
+
index_entity._link(ALL_PROVIDER_TAG_RELATION)
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
55
72
|
def get_index
|
56
|
-
|
57
|
-
@index_entity = Pact::Hal::Entity.new(response.body, http_client)
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_latest_tagged_pacts_for_provider
|
61
|
-
link = index_entity._link(LATEST_PROVIDER_TAG_RELATION)
|
62
|
-
tags.collect do | tag |
|
63
|
-
get_pact_urls(link.expand(provider: provider, tag: tag).get)
|
64
|
-
end.flatten
|
65
|
-
end
|
66
|
-
|
67
|
-
def get_all_tagged_pacts_for_provider
|
68
|
-
link = index_entity._link(ALL_PROVIDER_TAG_RELATION)
|
69
|
-
tags.collect do |tag|
|
70
|
-
get_pact_urls(link.expand(provider: provider, tag: tag).get)
|
71
|
-
end.flatten
|
73
|
+
@index_entity = Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
|
72
74
|
end
|
73
75
|
|
74
76
|
def get_latest_pacts_for_provider
|
@@ -76,14 +78,24 @@ module Pact
|
|
76
78
|
get_pact_urls(link.expand(provider: provider).get)
|
77
79
|
end
|
78
80
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
81
|
+
def get_pact_urls(link_by_provider)
|
82
|
+
link_by_provider.fetch(PACTS).collect do |pact|
|
83
|
+
Pact::Provider::PactURI.new(pact[HREF], http_client_options)
|
84
|
+
end
|
82
85
|
end
|
83
86
|
|
84
|
-
def
|
85
|
-
|
87
|
+
def log_message
|
88
|
+
message = "INFO: Fetching pacts for #{provider} from #{broker_base_url}"
|
89
|
+
if tags.any?
|
90
|
+
desc = tags.collect do |tag|
|
91
|
+
all_or_latest = tag[:all] ? "all" : "latest"
|
92
|
+
name = tag[:fallback] ? "#{tag[:name]} (or #{tag[:fallback]} if not found)" : tag[:name]
|
93
|
+
"#{all_or_latest} #{name}"
|
94
|
+
end.join(", ")
|
95
|
+
message << " for tags: #{desc}"
|
96
|
+
end
|
97
|
+
Pact.configuration.output_stream.puts message
|
86
98
|
end
|
87
99
|
end
|
88
100
|
end
|
89
|
-
end
|
101
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'pact/shared/dsl'
|
2
|
+
require 'pact/provider/world'
|
3
|
+
require 'pact/pact_broker/fetch_pacts'
|
4
|
+
|
5
|
+
module Pact
|
6
|
+
module Provider
|
7
|
+
module Configuration
|
8
|
+
class PactVerificationFromBroker
|
9
|
+
|
10
|
+
extend Pact::DSL
|
11
|
+
|
12
|
+
# If user declares a variable with the same name as one of these attributes
|
13
|
+
# in parent scope, it will clash with these ones,
|
14
|
+
# so put an underscore in front of the name to be safer.
|
15
|
+
|
16
|
+
attr_accessor :_provider_name, :_pact_broker_base_url, :_consumer_version_tags, :_basic_auth_options, :_verbose
|
17
|
+
|
18
|
+
def initialize(provider_name)
|
19
|
+
@_provider_name = provider_name
|
20
|
+
@_consumer_version_tags = []
|
21
|
+
@_verbose = false
|
22
|
+
end
|
23
|
+
|
24
|
+
dsl do
|
25
|
+
def pact_broker_base_url pact_broker_base_url, basic_auth_options = {}
|
26
|
+
self._pact_broker_base_url = pact_broker_base_url
|
27
|
+
self._basic_auth_options = basic_auth_options
|
28
|
+
end
|
29
|
+
|
30
|
+
def consumer_version_tags consumer_version_tags
|
31
|
+
self._consumer_version_tags = *consumer_version_tags
|
32
|
+
end
|
33
|
+
|
34
|
+
def verbose verbose
|
35
|
+
self._verbose = verbose
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def finalize
|
40
|
+
validate
|
41
|
+
create_pact_verification
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def create_pact_verification
|
47
|
+
fetch_pacts = Pact::PactBroker::FetchPacts.new(_provider_name, _consumer_version_tags, _pact_broker_base_url, _basic_auth_options.merge(verbose: _verbose))
|
48
|
+
Pact.provider_world.add_pact_uri_source fetch_pacts
|
49
|
+
end
|
50
|
+
|
51
|
+
def validate
|
52
|
+
raise Pact::Error.new("Please provide a pact_broker_base_url from which to retrieve the pacts") unless _pact_broker_base_url
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'pact/provider/configuration/pact_verification'
|
2
|
+
require 'pact/provider/configuration/pact_verification_from_broker'
|
2
3
|
require 'pact/provider/configuration/service_provider_config'
|
3
4
|
require 'pact/errors'
|
4
5
|
|
@@ -53,12 +54,20 @@ module Pact
|
|
53
54
|
def honours_pact_with consumer_name, options = {}, &block
|
54
55
|
create_pact_verification consumer_name, options, &block
|
55
56
|
end
|
57
|
+
|
58
|
+
def honours_pacts_from_pact_broker &block
|
59
|
+
create_pact_verification_from_broker &block
|
60
|
+
end
|
56
61
|
end
|
57
62
|
|
58
63
|
def create_pact_verification consumer_name, options, &block
|
59
64
|
PactVerification.build(consumer_name, options, &block)
|
60
65
|
end
|
61
66
|
|
67
|
+
def create_pact_verification_from_broker(&block)
|
68
|
+
PactVerificationFromBroker.build(name, &block)
|
69
|
+
end
|
70
|
+
|
62
71
|
def finalize
|
63
72
|
validate
|
64
73
|
create_service_provider
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module Pact::Provider
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
class PactVerification
|
3
|
+
attr_reader :consumer_name, :uri, :ref
|
4
|
+
def initialize consumer_name, uri, ref
|
5
|
+
@consumer_name = consumer_name
|
6
|
+
@uri = uri
|
7
|
+
@ref = ref
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def == other
|
11
|
+
other.is_a?(PactVerification) &&
|
12
|
+
consumer_name == other.consumer_name &&
|
13
|
+
uri == other.uri &&
|
14
|
+
ref == other.ref
|
15
|
+
end
|
16
|
+
end
|
17
17
|
end
|
data/lib/pact/provider/world.rb
CHANGED
@@ -29,8 +29,22 @@ module Pact
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def pact_urls
|
32
|
-
pact_verifications.collect(&:uri)
|
32
|
+
(pact_verifications.collect(&:uri) + pact_uris_from_pact_uri_sources).compact
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_pact_uri_source pact_uri_source
|
36
|
+
pact_uri_sources << pact_uri_source
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def pact_uri_sources
|
42
|
+
@pact_uri_sources ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def pact_uris_from_pact_uri_sources
|
46
|
+
pact_uri_sources.collect{| pact_uri_source| pact_uri_source.call }.flatten
|
33
47
|
end
|
34
48
|
end
|
35
49
|
end
|
36
|
-
end
|
50
|
+
end
|
data/lib/pact/version.rb
CHANGED
data/pact.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |gem|
|
|
33
33
|
|
34
34
|
gem.add_development_dependency 'rake', '~> 10.0.3'
|
35
35
|
gem.add_development_dependency 'webmock', '~> 3.0'
|
36
|
-
gem.add_development_dependency 'pry'
|
36
|
+
gem.add_development_dependency 'pry-byebug'
|
37
37
|
gem.add_development_dependency 'fakefs', '0.5' # 0.6.0 blows up
|
38
38
|
gem.add_development_dependency 'hashie', '~> 2.0'
|
39
39
|
gem.add_development_dependency 'activesupport'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.28.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fraser
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2018-06-
|
15
|
+
date: 2018-06-24 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: randexp
|
@@ -175,7 +175,7 @@ dependencies:
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '3.0'
|
177
177
|
- !ruby/object:Gem::Dependency
|
178
|
-
name: pry
|
178
|
+
name: pry-byebug
|
179
179
|
requirement: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - ">="
|
@@ -342,6 +342,7 @@ files:
|
|
342
342
|
- lib/pact/provider/configuration/configuration_extension.rb
|
343
343
|
- lib/pact/provider/configuration/dsl.rb
|
344
344
|
- lib/pact/provider/configuration/pact_verification.rb
|
345
|
+
- lib/pact/provider/configuration/pact_verification_from_broker.rb
|
345
346
|
- lib/pact/provider/configuration/service_provider_config.rb
|
346
347
|
- lib/pact/provider/configuration/service_provider_dsl.rb
|
347
348
|
- lib/pact/provider/context.rb
|
@@ -402,9 +403,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
402
403
|
version: '2.0'
|
403
404
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
404
405
|
requirements:
|
405
|
-
- - "
|
406
|
+
- - ">"
|
406
407
|
- !ruby/object:Gem::Version
|
407
|
-
version:
|
408
|
+
version: 1.3.1
|
408
409
|
requirements: []
|
409
410
|
rubyforge_project:
|
410
411
|
rubygems_version: 2.6.11
|