pact-mock_service 2.12.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/pact/consumer/server.rb +4 -7
- data/lib/pact/mock_service/app_manager.rb +15 -15
- data/lib/pact/mock_service/cli.rb +4 -2
- data/lib/pact/mock_service/client.rb +5 -4
- data/lib/pact/mock_service/control_server/mock_service_creator.rb +1 -2
- data/lib/pact/mock_service/control_server/run.rb +1 -0
- data/lib/pact/mock_service/run.rb +1 -1
- data/lib/pact/mock_service/spawn.rb +7 -6
- data/lib/pact/mock_service/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c70b1c91a2cb0c5669764a493b1a40e54ef899de89d31f2cabf67479b440fde
|
4
|
+
data.tar.gz: 1b3a5b28fd448a55d59ca38c4d21a85fb5eb9de2bfbe313a0746376dd179502d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6beed9671e9c090c7b9d755566f1c7f78b3b4f5972e91f9de4cc8a5f9b42dfbd22d43d6cd13f201d58abf570e2e9abfc5646ea73508dd31d38b5069132432a0a
|
7
|
+
data.tar.gz: ecc5d8264e776a7ee712acdfa2d5eee037380c0380fd40ca51c8e1eff01166bc8a181e603b7e7b718b6ec07fc63ea583286523664f3845c599c2043ac6aa3bfc
|
data/CHANGELOG.md
CHANGED
data/lib/pact/consumer/server.rb
CHANGED
@@ -34,12 +34,13 @@ module Pact
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
attr_reader :app, :port, :options
|
37
|
+
attr_reader :app, :host, :port, :options
|
38
38
|
|
39
|
-
def initialize(app, port, options = {})
|
39
|
+
def initialize(app, host, port, options = {})
|
40
40
|
@app = app
|
41
41
|
@middleware = Middleware.new(@app)
|
42
42
|
@server_thread = nil
|
43
|
+
@host = host
|
43
44
|
@port = port
|
44
45
|
@options = options
|
45
46
|
end
|
@@ -52,10 +53,6 @@ module Pact
|
|
52
53
|
@middleware.error
|
53
54
|
end
|
54
55
|
|
55
|
-
def host
|
56
|
-
"localhost"
|
57
|
-
end
|
58
|
-
|
59
56
|
def responsive?
|
60
57
|
return false if @server_thread && @server_thread.join(0)
|
61
58
|
res = get_identity
|
@@ -96,7 +93,7 @@ module Pact
|
|
96
93
|
end
|
97
94
|
|
98
95
|
def ssl_opts
|
99
|
-
{ SSLEnable: true, SSLCertName: [
|
96
|
+
{ SSLEnable: true, SSLCertName: [ ["CN", host] ] }
|
100
97
|
end
|
101
98
|
|
102
99
|
def boot
|
@@ -23,7 +23,6 @@ module Pact
|
|
23
23
|
def register_mock_service_for(name, url, options = {})
|
24
24
|
uri = URI(url)
|
25
25
|
raise "Currently only http is supported" unless uri.scheme == 'http'
|
26
|
-
raise "Currently only services on localhost are supported" unless uri.host == 'localhost'
|
27
26
|
uri.port = nil if options[:find_available_port]
|
28
27
|
|
29
28
|
app = Pact::MockService.new(
|
@@ -32,21 +31,21 @@ module Pact
|
|
32
31
|
pact_dir: pact_dir,
|
33
32
|
pact_specification_version: options.fetch(:pact_specification_version)
|
34
33
|
)
|
35
|
-
register(app, uri.port)
|
34
|
+
register(app, uri.host, uri.port)
|
36
35
|
end
|
37
36
|
|
38
|
-
def register(app, port = nil)
|
37
|
+
def register(app, host, port = nil)
|
39
38
|
if port
|
40
|
-
existing =
|
39
|
+
existing = existing_app_on_host_and_port(host, port)
|
41
40
|
raise "Port #{port} is already being used by #{existing}" if existing and not existing == app
|
42
41
|
end
|
43
|
-
app_registration = register_app(app, port)
|
42
|
+
app_registration = register_app(app, host, port)
|
44
43
|
app_registration.spawn
|
45
44
|
app_registration.port
|
46
45
|
end
|
47
46
|
|
48
|
-
def
|
49
|
-
app_registrations.find_all(&:is_a_mock_service?).collect
|
47
|
+
def urls_of_mock_services
|
48
|
+
app_registrations.find_all(&:is_a_mock_service?).collect{ |ar| "http://#{ar.host}:#{ar.port}" }
|
50
49
|
end
|
51
50
|
|
52
51
|
def kill_all
|
@@ -70,13 +69,13 @@ module Pact
|
|
70
69
|
|
71
70
|
private
|
72
71
|
|
73
|
-
def
|
74
|
-
app_registration =
|
72
|
+
def existing_app_on_host_and_port(host, port)
|
73
|
+
app_registration = registration_on_host_and_port(host, port)
|
75
74
|
app_registration ? app_registration.app : nil
|
76
75
|
end
|
77
76
|
|
78
|
-
def
|
79
|
-
@app_registrations.find { |app_registration| app_registration.port == port }
|
77
|
+
def registration_on_host_and_port(host, port)
|
78
|
+
@app_registrations.find { |app_registration| app_registration.port == port && app_registration.host == host }
|
80
79
|
end
|
81
80
|
|
82
81
|
def pact_dir
|
@@ -107,8 +106,8 @@ module Pact
|
|
107
106
|
@app_registrations
|
108
107
|
end
|
109
108
|
|
110
|
-
def register_app(app, port)
|
111
|
-
app_registration = AppRegistration.new(app: app, port: port)
|
109
|
+
def register_app(app, host, port)
|
110
|
+
app_registration = AppRegistration.new(app: app, host: host, port: port)
|
112
111
|
app_registrations << app_registration
|
113
112
|
app_registration
|
114
113
|
end
|
@@ -116,11 +115,12 @@ module Pact
|
|
116
115
|
|
117
116
|
class AppRegistration
|
118
117
|
include Pact::Logging
|
119
|
-
attr_accessor :port, :app
|
118
|
+
attr_accessor :host, :port, :app
|
120
119
|
|
121
120
|
def initialize(opts)
|
122
121
|
@max_wait = 10
|
123
122
|
@port = opts[:port]
|
123
|
+
@host = opts[:host]
|
124
124
|
@app = opts[:app]
|
125
125
|
@spawned = false
|
126
126
|
end
|
@@ -148,7 +148,7 @@ module Pact
|
|
148
148
|
|
149
149
|
def spawn
|
150
150
|
logger.info "Starting app #{self}..."
|
151
|
-
@server = Pact::Server.new(app, port).boot
|
151
|
+
@server = Pact::Server.new(app, host, port).boot
|
152
152
|
@port = @server.port
|
153
153
|
@spawned = true
|
154
154
|
logger.info "Started on port #{port}"
|
@@ -107,6 +107,7 @@ module Pact
|
|
107
107
|
|
108
108
|
desc 'control-start', "Start a Pact mock service control server."
|
109
109
|
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '1234'
|
110
|
+
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
|
110
111
|
method_option :log_dir, aliases: "-l", desc: "File to which to log output", default: "log"
|
111
112
|
method_option :log_level, desc: "Log level. Options are DEBUG INFO WARN ERROR", default: "DEBUG"
|
112
113
|
method_option :pact_file_write_mode, aliases: "-m", desc: PACT_FILE_WRITE_MODE_DESC, type: :string, default: 'overwrite'
|
@@ -134,6 +135,7 @@ module Pact
|
|
134
135
|
|
135
136
|
desc 'control-restart', "Start a Pact mock service control server."
|
136
137
|
method_option :port, aliases: "-p", desc: "Port on which to run the service", default: '1234'
|
138
|
+
method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
|
137
139
|
method_option :log_dir, aliases: "-l", desc: "File to which to log output", default: "log"
|
138
140
|
method_option :log_level, desc: "Log level. Options are DEBUG INFO WARN ERROR", default: "DEBUG"
|
139
141
|
method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."
|
@@ -180,14 +182,14 @@ module Pact
|
|
180
182
|
|
181
183
|
def start_server pidfile
|
182
184
|
require 'pact/mock_service/server/spawn'
|
183
|
-
Pact::MockService::Server::Spawn.(pidfile, options[:port], options[:ssl]) do
|
185
|
+
Pact::MockService::Server::Spawn.(pidfile, options[:host], options[:port], options[:ssl]) do
|
184
186
|
yield
|
185
187
|
end
|
186
188
|
end
|
187
189
|
|
188
190
|
def restart_server pidfile
|
189
191
|
require 'pact/mock_service/server/respawn'
|
190
|
-
Pact::MockService::Server::Respawn.(pidfile, options[:port], options[:ssl]) do
|
192
|
+
Pact::MockService::Server::Respawn.(pidfile, options[:host], options[:port], options[:ssl]) do
|
191
193
|
yield
|
192
194
|
end
|
193
195
|
end
|
@@ -13,8 +13,8 @@ module Pact
|
|
13
13
|
|
14
14
|
MOCK_SERVICE_ADMINISTRATON_HEADERS = {'X-Pact-Mock-Service' => 'true'}
|
15
15
|
|
16
|
-
def initialize port
|
17
|
-
@http = Net::HTTP.new(
|
16
|
+
def initialize port, host = 'localhost'
|
17
|
+
@http = Net::HTTP.new(host, port)
|
18
18
|
end
|
19
19
|
|
20
20
|
def verify example_description
|
@@ -46,8 +46,9 @@ module Pact
|
|
46
46
|
raise AddInteractionError.new("\e[31m#{response.body}\e[m") unless response.is_a? Net::HTTPSuccess
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.clear_interactions
|
50
|
-
|
49
|
+
def self.clear_interactions mock_service_base_url, example_description
|
50
|
+
uri = URI(mock_service_base_url)
|
51
|
+
Net::HTTP.new(uri.host, uri.port).delete("/interactions?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS)
|
51
52
|
end
|
52
53
|
|
53
54
|
def write_pact pacticipant_details
|
@@ -8,7 +8,6 @@ require 'pact/mock_service/server/wait_for_server_up'
|
|
8
8
|
module Pact
|
9
9
|
module MockService
|
10
10
|
module ControlServer
|
11
|
-
|
12
11
|
class MockServiceCreator
|
13
12
|
|
14
13
|
attr_reader :options
|
@@ -22,7 +21,7 @@ module Pact
|
|
22
21
|
consumer_name = env['HTTP_X_PACT_CONSUMER']
|
23
22
|
provider_name = env['HTTP_X_PACT_PROVIDER']
|
24
23
|
port = FindAPort.available_port
|
25
|
-
mock_service = Pact::MockService::Spawn.(consumer_name, provider_name, port, options)
|
24
|
+
mock_service = Pact::MockService::Spawn.(consumer_name, provider_name, options[:host] || 'localhost', port, options)
|
26
25
|
delegator = Delegator.new(mock_service, consumer_name, provider_name)
|
27
26
|
@mock_services.add(delegator)
|
28
27
|
delegator.call(env)
|
@@ -8,15 +8,16 @@ module Pact
|
|
8
8
|
module MockService
|
9
9
|
class Spawn
|
10
10
|
|
11
|
-
def self.call consumer, provider, port, options
|
12
|
-
new(consumer, provider, port, options).call
|
11
|
+
def self.call consumer, provider, host, port, options
|
12
|
+
new(consumer, provider, host, port, options).call
|
13
13
|
end
|
14
14
|
|
15
|
-
attr_reader :consumer, :provider, :port, :options
|
15
|
+
attr_reader :consumer, :provider, :host, :port, :options
|
16
16
|
|
17
|
-
def initialize consumer, provider, port, options
|
17
|
+
def initialize consumer, provider, host, port, options
|
18
18
|
@consumer = consumer
|
19
19
|
@provider = provider
|
20
|
+
@host = host
|
20
21
|
@port = port
|
21
22
|
@options = options
|
22
23
|
end
|
@@ -49,7 +50,7 @@ module Pact
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def start_mock_service app, port
|
52
|
-
Pact::Server.new(app, port, ssl: options[:ssl]).boot
|
53
|
+
Pact::Server.new(app, host, port, ssl: options[:ssl]).boot
|
53
54
|
end
|
54
55
|
|
55
56
|
def create_log_file
|
@@ -73,7 +74,7 @@ module Pact
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def base_url
|
76
|
-
options[:ssl] ? "https
|
77
|
+
options[:ssl] ? "https://#{host}:#{port}" : "http://#{host}:#{port}"
|
77
78
|
end
|
78
79
|
|
79
80
|
def name
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact-mock_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
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:
|
15
|
+
date: 2019-02-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rack
|
@@ -399,8 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
399
399
|
- !ruby/object:Gem::Version
|
400
400
|
version: '0'
|
401
401
|
requirements: []
|
402
|
-
|
403
|
-
rubygems_version: 2.7.7
|
402
|
+
rubygems_version: 3.0.2
|
404
403
|
signing_key:
|
405
404
|
specification_version: 4
|
406
405
|
summary: Provides a mock service for use with Pact
|