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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bbf7164320c9bac3a7095a73727fb1bc887e3e3900e5bea8ed9103ea5391c37
4
- data.tar.gz: 7dcda5c9871021cbb95b7ccf27fba2ce9194d81c8fcdbd0c5525b87dece84c81
3
+ metadata.gz: 9c70b1c91a2cb0c5669764a493b1a40e54ef899de89d31f2cabf67479b440fde
4
+ data.tar.gz: 1b3a5b28fd448a55d59ca38c4d21a85fb5eb9de2bfbe313a0746376dd179502d
5
5
  SHA512:
6
- metadata.gz: 1ea38269c2c3c075fcf526078cd30a640e1667df424c8bec2f1c1c38450ea4ade5eb08727b119f94051449fae2d92ba274f166102811db0a55e01cda4d1e5322
7
- data.tar.gz: db1687563fc2e96fdadb86c737c9c534b0294b8d1454d373a43e732733f49f14e3483580beb8c72e74aa7c767d15b36cbfacf993706c6bf563c66ad24a145354
6
+ metadata.gz: 6beed9671e9c090c7b9d755566f1c7f78b3b4f5972e91f9de4cc8a5f9b42dfbd22d43d6cd13f201d58abf570e2e9abfc5646ea73508dd31d38b5069132432a0a
7
+ data.tar.gz: ecc5d8264e776a7ee712acdfa2d5eee037380c0380fd40ca51c8e1eff01166bc8a181e603b7e7b718b6ec07fc63ea583286523664f3845c599c2043ac6aa3bfc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ <a name="v3.0.0"></a>
2
+ ### v3.0.0 (2019-02-21)
3
+
4
+
5
+ #### Features
6
+
7
+ * allow mock service host to be configured ([7e2d810](/../../commit/7e2d810))
8
+
9
+
1
10
  <a name="v2.11.0"></a>
2
11
  ### v2.11.0 (2018-08-28)
3
12
 
@@ -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: [ %w[CN localhost] ] }
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 = existing_app_on_port(port)
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 ports_of_mock_services
49
- app_registrations.find_all(&:is_a_mock_service?).collect(&:port)
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 existing_app_on_port(port)
74
- app_registration = registration_on_port(port)
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 registration_on_port(port)
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('localhost', port)
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 port, example_description
50
- Net::HTTP.new("localhost", port).delete("/interactions?example_description=#{CGI.escape(example_description)}", MOCK_SERVICE_ADMINISTRATON_HEADERS)
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)
@@ -55,6 +55,7 @@ module Pact
55
55
  unique_pact_file_names: options[:unique_pact_file_names],
56
56
  cors_enabled: options[:cors] || false,
57
57
  ssl: options[:ssl],
58
+ host: options[:host],
58
59
  pact_specification_version: options[:pact_specification_version]
59
60
  }
60
61
  end
@@ -98,7 +98,7 @@ module Pact
98
98
  def ssl_opts
99
99
  {
100
100
  :SSLEnable => true,
101
- :SSLCertName => [ %w[CN localhost] ]
101
+ :SSLCertName => [ ["CN", host] ]
102
102
  }
103
103
  end
104
104
 
@@ -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://localhost:#{port}" : "http://localhost:#{port}"
77
+ options[:ssl] ? "https://#{host}:#{port}" : "http://#{host}:#{port}"
77
78
  end
78
79
 
79
80
  def name
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module MockService
3
- VERSION = "2.12.0"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
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: 2.12.0
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: 2018-10-03 00:00:00.000000000 Z
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
- rubyforge_project:
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