pact-mock_service 0.8.1 → 0.8.2

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
  SHA1:
3
- metadata.gz: 5608731e44a840bffd2027c74f46063358559524
4
- data.tar.gz: 010ace178b9dbf2a13ae9958980052aa5d9fe311
3
+ metadata.gz: b2fe31dd5077800edd5307e100979a92d3056eb9
4
+ data.tar.gz: cae8ad2a915922e11bab37deb7e38dbc6a467314
5
5
  SHA512:
6
- metadata.gz: f0907e1d76e88a74d3826c1eba4615675a12bd7e1f5ae4e8e1ce2c083cda257d0fd9f3cb33e1ee137174ad8ba1bf62363a040a887afbb20f01ab9668a8708aff
7
- data.tar.gz: 32ad9969e394768166b7aa66f7b4b447c4e35dea5c12666309a691597aff027d67d2314e2d4e7e9659cee00b01654ea4b4c091ccff8db25fbfd130799731a27f
6
+ metadata.gz: 8156beaceb8f03bc993d9510455fc194fe7dc60705521621cf016b660f73ef1a58cde961f322fcde32f76c02745800523a824b345a2e4ccda3f1dc90c564c7c6
7
+ data.tar.gz: 50b3011a79bd77eb5f905433ec9e78b31450925acbb79da724e6630ae65da005920be792b90c4c243da26c07354f2055920bb2102d3c9542dadbf25772cf1d9f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@ Do this to generate your change history
2
2
 
3
3
  git log --pretty=format:' * %h - %s (%an, %ad)' vX.Y.Z..HEAD
4
4
 
5
+ ### 0.8.2 (19 April 2016)
6
+ * e392333 - Merge pull request #45 from aaronrenner/ar-fix-almost-duplicate-error-web-response (Beth Skurrie, Tue Apr 19 09:53:01 2016 +1000)
7
+ * 6fbcce2 - Fixed invalid Rack response on AlmostDuplicateInteractionError (Aaron Renner, Mon Apr 18 14:08:19 2016 -0600)
8
+ * 2cdce52 - Merge pull request #44 from sebdiem/sebdiem/add_host_option (Sergei Matheson, Tue Mar 29 09:23:35 2016 +1100)
9
+ * a76a321 - add host option for control server (Sébastien Diemer, Sun Mar 27 23:25:19 2016 +0200)
10
+ * aadbb8d - Merge pull request #43 from taiki45/find-available-port-option (Sergei Matheson, Mon Mar 21 09:35:40 2016 +1100)
11
+ * 98c9233 - remove --pact-dir from the windows bat file #41 (Ron Holshausen, Fri Mar 18 11:42:22 2016 +1100)
12
+ * f4c2fa5 - Fix timing issue on server test (Taiki Ono, Thu Mar 17 17:24:22 2016 +0900)
13
+ * 0655161 - Format code (Taiki Ono, Thu Mar 17 00:19:45 2016 +0900)
14
+ * fbea6d4 - Support find_available_port option (Taiki Ono, Wed Mar 16 19:12:36 2016 +0900)
15
+ * e72b0cd - WEBrick expects port as Integer (Taiki Ono, Wed Feb 24 19:16:57 2016 +0900)
16
+ * 9580c41 - Merge pull request #42 from taiki45/update-travis-ci-setting (Sergei Matheson, Wed Mar 16 19:59:08 2016 +1100)
17
+ * 01b90e0 - Update Travis CI setting with new Rubies (Taiki Ono, Sun Mar 13 21:19:43 2016 +0900)
18
+
5
19
 
6
20
  ### 0.8.1 (25 February 2016)
7
21
  * ffa37f8 - Merge pull request #40 from taiki45/add-option-not-to-write-pact-file (Beth Skurrie, Thu Feb 25 09:33:30 2016 +1100)
@@ -70,10 +70,13 @@ module Pact
70
70
 
71
71
  def run_default_server(app, port)
72
72
  require 'rack/handler/webrick'
73
- Rack::Handler::WEBrick.run(app, webrick_opts)
73
+ Rack::Handler::WEBrick.run(app, webrick_opts) do |server|
74
+ @port = server[:Port]
75
+ end
74
76
  end
75
77
 
76
78
  def get_identity
79
+ return false unless @port
77
80
  http = Net::HTTP.new host, @port
78
81
  if options[:ssl]
79
82
  http.use_ssl = true
@@ -83,33 +86,25 @@ module Pact
83
86
  end
84
87
 
85
88
  def webrick_opts
86
- opts = {:Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0)}
89
+ opts = {Port: port.nil? ? 0 : port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0)}
87
90
  opts.merge!(ssl_opts) if options[:ssl]
88
91
  opts
89
92
  end
90
93
 
91
94
  def ssl_opts
92
- {
93
- :SSLEnable => true,
94
- :SSLCertName => [ %w[CN localhost] ]
95
- }
95
+ { SSLEnable: true, SSLCertName: [ %w[CN localhost] ] }
96
96
  end
97
97
 
98
98
  def boot
99
99
  unless responsive?
100
- Pact::Server.ports[@app.object_id] = @port
101
-
102
- @server_thread = Thread.new do
103
- run_default_server(@middleware, @port)
104
- end
105
-
100
+ @server_thread = Thread.new { run_default_server(@middleware, @port) }
106
101
  Timeout.timeout(60) { @server_thread.join(0.1) until responsive? }
107
102
  end
108
103
  rescue Timeout::Error
109
104
  raise "Rack application timed out during boot"
110
105
  else
106
+ Pact::Server.ports[@app.object_id] = @port
111
107
  self
112
108
  end
113
-
114
109
  end
115
110
  end
@@ -2,12 +2,10 @@ require 'thwait'
2
2
 
3
3
  require 'net/http'
4
4
  require 'uri'
5
- require 'find_a_port'
6
5
  require 'pact/logging'
7
6
  require 'pact/consumer/server'
8
7
  require 'singleton'
9
8
  require 'pact/mock_service/app'
10
- require 'find_a_port'
11
9
 
12
10
  module Pact
13
11
  module MockService
@@ -22,20 +20,29 @@ module Pact
22
20
  @app_registrations = []
23
21
  end
24
22
 
25
- def register_mock_service_for name, url, options = {}
23
+ def register_mock_service_for(name, url, options = {})
26
24
  uri = URI(url)
27
25
  raise "Currently only http is supported" unless uri.scheme == 'http'
28
26
  raise "Currently only services on localhost are supported" unless uri.host == 'localhost'
27
+ uri.port = nil if options[:find_available_port]
29
28
 
30
- register(Pact::MockService.new(log_file: create_log_file(name), name: name, pact_dir: pact_dir, pact_specification_version: options[:pact_specification_version]), uri.port)
29
+ app = Pact::MockService.new(
30
+ name: name,
31
+ log_file: create_log_file(name),
32
+ pact_dir: pact_dir,
33
+ pact_specification_version: options[:pact_specification_version]
34
+ )
35
+ register(app, uri.port)
31
36
  end
32
37
 
33
- def register(app, port = FindAPort.available_port)
34
- existing = existing_app_on_port port
35
- raise "Port #{port} is already being used by #{existing}" if existing and not existing == app
36
- app_registration = register_app app, port
37
- app_registration.spawn if @apps_spawned
38
- port
38
+ def register(app, port = nil)
39
+ if port
40
+ existing = existing_app_on_port(port)
41
+ raise "Port #{port} is already being used by #{existing}" if existing and not existing == app
42
+ end
43
+ app_registration = register_app(app, port)
44
+ app_registration.spawn
45
+ app_registration.port
39
46
  end
40
47
 
41
48
  def ports_of_mock_services
@@ -63,12 +70,12 @@ module Pact
63
70
 
64
71
  private
65
72
 
66
- def existing_app_on_port port
67
- app_registration = registration_on_port port
73
+ def existing_app_on_port(port)
74
+ app_registration = registration_on_port(port)
68
75
  app_registration ? app_registration.app : nil
69
76
  end
70
77
 
71
- def registration_on_port port
78
+ def registration_on_port(port)
72
79
  @app_registrations.find { |app_registration| app_registration.port == port }
73
80
  end
74
81
 
@@ -76,18 +83,18 @@ module Pact
76
83
  Pact.configuration.pact_dir
77
84
  end
78
85
 
79
- def create_log_file service_name
80
- FileUtils::mkdir_p Pact.configuration.log_dir
86
+ def create_log_file(service_name)
87
+ FileUtils::mkdir_p(Pact.configuration.log_dir)
81
88
  log = File.open(log_file_path(service_name), 'w')
82
89
  log.sync = true
83
90
  log
84
91
  end
85
92
 
86
- def log_file_path service_name
93
+ def log_file_path(service_name)
87
94
  File.join(Pact.configuration.log_dir, "#{log_file_name(service_name)}.log")
88
95
  end
89
96
 
90
- def log_file_name service_name
97
+ def log_file_name(service_name)
91
98
  lower_case_name = service_name.downcase.gsub(/\s+/, '_')
92
99
  if lower_case_name.include?('_service')
93
100
  lower_case_name.gsub('_service', '_mock_service')
@@ -100,8 +107,8 @@ module Pact
100
107
  @app_registrations
101
108
  end
102
109
 
103
- def register_app app, port
104
- app_registration = AppRegistration.new :app => app, :port => port
110
+ def register_app(app, port)
111
+ app_registration = AppRegistration.new(app: app, port: port)
105
112
  app_registrations << app_registration
106
113
  app_registration
107
114
  end
@@ -109,10 +116,9 @@ module Pact
109
116
 
110
117
  class AppRegistration
111
118
  include Pact::Logging
112
- attr_accessor :port
113
- attr_accessor :app
119
+ attr_accessor :port, :app
114
120
 
115
- def initialize opts
121
+ def initialize(opts)
116
122
  @max_wait = 10
117
123
  @port = opts[:port]
118
124
  @app = opts[:app]
@@ -133,7 +139,7 @@ module Pact
133
139
  end
134
140
 
135
141
  def is_a_mock_service?
136
- app.is_a? Pact::MockService::App
142
+ app.is_a?(Pact::MockService::App)
137
143
  end
138
144
 
139
145
  def to_s
@@ -143,6 +149,7 @@ module Pact
143
149
  def spawn
144
150
  logger.info "Starting app #{self}..."
145
151
  @server = Pact::Server.new(app, port).boot
152
+ @port = @server.port
146
153
  @spawned = true
147
154
  logger.info "Started on port #{port}"
148
155
  end
@@ -28,6 +28,7 @@ module Pact
28
28
 
29
29
  desc 'control', "Run a Pact mock service control server."
30
30
  method_option :port, aliases: "-p", desc: "Port on which to run the service"
31
+ method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
31
32
  method_option :log_dir, aliases: "-l", desc: "File to which to log output"
32
33
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
33
34
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
@@ -59,6 +59,7 @@ module Pact
59
59
  def webbrick_opts
60
60
  {
61
61
  :Port => options[:port],
62
+ :Host => options[:host],
62
63
  :AccessLog => []
63
64
  }
64
65
  end
@@ -28,7 +28,7 @@ module Pact
28
28
  session.set_expected_interactions interactions
29
29
  [200, {}, ['Set interactions']]
30
30
  rescue AlmostDuplicateInteractionError => e
31
- [500, {}, e.message]
31
+ [500, {}, [e.message]]
32
32
  end
33
33
  end
34
34
 
@@ -83,7 +83,7 @@ module Pact
83
83
  end
84
84
 
85
85
  def port
86
- @port ||= options[:port] || FindAPort.available_port
86
+ @port ||= (options[:port] || FindAPort.available_port).to_i
87
87
  end
88
88
 
89
89
  def host
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module MockService
3
- VERSION = "0.8.1"
3
+ VERSION = "0.8.2"
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: 0.8.1
4
+ version: 0.8.2
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: 2016-02-25 00:00:00.000000000 Z
15
+ date: 2016-04-19 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -331,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
331
331
  version: '0'
332
332
  requirements: []
333
333
  rubyforge_project:
334
- rubygems_version: 2.2.2
334
+ rubygems_version: 2.4.5
335
335
  signing_key:
336
336
  specification_version: 4
337
337
  summary: Provides a mock service for use with Pact