pact-mock_service 2.1.1.pre.alpha.2 → 2.2.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
  SHA1:
3
- metadata.gz: 5693645528ece7ef91958e2598f64bba38215104
4
- data.tar.gz: 3a57c015eb730e45150a23a0b63b818461e61cbc
3
+ metadata.gz: 0cf900a12d4f91a4ff30a3e9f524f989ffedca18
4
+ data.tar.gz: ac91a2457b5d83c349c70663682dfae00e22af08
5
5
  SHA512:
6
- metadata.gz: e64fe9e5ed774d2bef6f2a2b8746b5dbb9f6e46ff586ebc37957c0bd9719444b31972dbb5aaf43b52046b85752bd0d2cc628102233d486387a97d07d26a362f1
7
- data.tar.gz: 9713fb5b520bcff76a6e45aafb88dd17835e311a907e88288f4a3b6502c702a287af7cf6acb9af8b7f670371e8000f33aaed214db7d57555bf753bfa79936046
6
+ metadata.gz: 296f813db0e501057558d0cdb241b56fba89144be5822f2aac010b9cfbdabf960ae644a4a508eb6ae37192b042901f3180a093a210e7c3372ee20ba3db487598
7
+ data.tar.gz: fbc2b07d41210eaf4fafe758e6135c9ca41bfe9038a5d8f327eb5dd86ef6fb9a89d81d82f0a4caaa8a0fbf6a1c46f2b1c68ce2efc7e0444f3792631a3cf57c0a
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@ 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
+ ### 2.2.0 (2017-09-30)
6
+ * 3949e3d - feat(cli): add --unique-pact-file-names option (Beth Skurrie, Thu Sep 28 11:16:22 2017 +1000)
7
+
5
8
  ### 2.1.0 (12 May 2017)
6
9
  * 5b89d95 - Updated location of pact specification version in pact to metadata.pactSpecification.version. As per issue #137 (Beth Skurrie, Fri May 12 11:03:54 2017 +1000)
7
10
  * b85ad94 - Update mock service interaction decorator to use providerState between the consumer DSL and the mock service, just to avoid any further confusion! (Beth Skurrie, Fri May 12 08:41:56 2017 +1000)
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ gemspec
5
5
 
6
6
  if ENV['X_PACT_DEVELOPMENT']
7
7
  gem 'pact-support', path: '../pact-support'
8
- end
8
+ end
@@ -129,7 +129,7 @@ module Pact
129
129
 
130
130
  def pactfile_path
131
131
  raise 'You must specify a consumer and provider name' unless (consumer_name && provider_name)
132
- file_path consumer_name, provider_name, pact_dir
132
+ file_path consumer_name, provider_name, pact_dir, unique: consumer_contract_details[:unique_pact_file_names]
133
133
  end
134
134
 
135
135
  def pact_dir
@@ -5,7 +5,6 @@ require 'fileutils'
5
5
  require 'pact/mock_service/server/wait_for_server_up'
6
6
  require 'pact/mock_service/cli/pidfile'
7
7
  require 'socket'
8
- require 'rake/file_utils'
9
8
 
10
9
  module Pact
11
10
  module MockService
@@ -20,6 +19,7 @@ module Pact
20
19
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
21
20
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
22
21
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
22
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
23
23
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
24
24
  method_option :consumer, desc: "Consumer name"
25
25
  method_option :provider, desc: "Provider name"
@@ -34,6 +34,7 @@ module Pact
34
34
  method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
35
35
  method_option :log_dir, aliases: "-l", desc: "File to which to log output"
36
36
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
37
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
37
38
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
38
39
  method_option :ssl, desc: "Use a self-signed SSL cert to run the service over HTTPS", type: :boolean, default: false
39
40
  method_option :sslcert, desc: "Specify the path to the SSL cert to use when running the service over HTTPS"
@@ -54,13 +55,16 @@ module Pact
54
55
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
55
56
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
56
57
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
58
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
57
59
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
58
60
  method_option :consumer, desc: "Consumer name"
59
61
  method_option :provider, desc: "Provider name"
60
62
  method_option :pid_dir, desc: "PID dir", default: 'tmp/pids'
61
63
 
62
64
  def start
63
- spawn_mock_service
65
+ start_server(mock_service_pidfile) do
66
+ service
67
+ end
64
68
  end
65
69
 
66
70
  desc 'stop', "Stop a Pact mock service"
@@ -80,6 +84,7 @@ module Pact
80
84
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
81
85
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
82
86
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written"
87
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
83
88
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
84
89
  method_option :consumer, desc: "Consumer name"
85
90
  method_option :provider, desc: "Provider name"
@@ -99,6 +104,7 @@ module Pact
99
104
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
100
105
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
101
106
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."
107
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
102
108
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
103
109
  method_option :pid_dir, desc: "PID dir", default: "tmp/pids"
104
110
 
@@ -124,6 +130,7 @@ module Pact
124
130
  method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
125
131
  method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
126
132
  method_option :pact_dir, aliases: "-d", desc: "Directory to which the pacts will be written", default: "."
133
+ method_option :unique_pact_file_names, aliases: "-u", desc: "Set to true when running multiple mock service instances in parallel for the same consumer/provider pair", type: :boolean, default: false
127
134
  method_option :pact_specification_version, aliases: "-i", desc: "The pact specification version to use when writing the pact", default: '1'
128
135
  method_option :pid_dir, desc: "PID dir", default: "tmp/pids"
129
136
 
@@ -173,34 +180,6 @@ module Pact
173
180
  yield
174
181
  end
175
182
  end
176
-
177
- def spawn_mock_service
178
- require 'pact/mock_service/server/windows_safe_spawn'
179
- pidfile = mock_service_pidfile
180
- Pact::MockService::Server::WindowsSafeSpawn.(service_spawn_command, pidfile, options[:port], options[:ssl])
181
- end
182
-
183
- def service_spawn_command
184
- command = []
185
- if ENV['PACT_STANDALONE_WRAPPER_PATH']
186
- command << ENV['PACT_STANDALONE_WRAPPER_PATH']
187
- else
188
- command << FileUtils::RUBY
189
- command << "-S #{$0}"
190
- end
191
- command << "service"
192
- command += build_service_options
193
- command.join(" ")
194
- end
195
-
196
- def service_switch_names
197
- Pact::MockService::CLI.commands['service'].options.values.each_with_object({}){| option, hash| hash[option.human_name] = option.switch_name }
198
- end
199
-
200
- def build_service_options
201
- switch_names = service_switch_names
202
- options.collect{ |key, value| "#{switch_names[key]} #{value}" if switch_names[key] }.compact
203
- end
204
183
  end
205
184
  end
206
185
  end
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- require 'pact/mock_service/os'
3
2
 
4
3
  module Pact
5
4
  module MockService
@@ -74,13 +73,14 @@ module Pact
74
73
  sleep sleep_time
75
74
  tries += 1
76
75
  end
77
- raise "Process #{pid_from_file} not stopped after #{100 * sleep_time} seconds." if process_running?
76
+ raise "Process #{pid_from_file} not stopped after {100 * sleep_time} seconds." if process_running?
78
77
  end
79
78
 
80
79
  def kill_process
81
80
  if file_exists?
82
81
  begin
83
- windows? ? windows_kill : kill_2
82
+ `ps -ef | grep pact`
83
+ Process.kill 2, pid_from_file
84
84
  waitpid
85
85
  delete
86
86
  rescue Errno::ESRCH
@@ -91,19 +91,6 @@ module Pact
91
91
  $stderr.puts "No PID file found at #{pidfile_path}, server probably not running. Use `ps -ef | grep pact` if you suspect the process is still running."
92
92
  end
93
93
  end
94
-
95
- def windows?
96
- Pact::MockService::OS.windows?
97
- end
98
-
99
- def kill_2
100
- Process.kill 2, pid_from_file
101
- end
102
-
103
- def windows_kill
104
- cmd = "taskkill /f /pid #{pid_from_file}"
105
- `#{cmd}`
106
- end
107
94
  end
108
95
  end
109
96
  end
@@ -51,6 +51,7 @@ module Pact
51
51
  {
52
52
  log_dir: options[:log_dir] || "log",
53
53
  pact_dir: options[:pact_dir] || ".",
54
+ unique_pact_file_names: options[:unique_pact_file_names],
54
55
  cors_enabled: options[:cors] || false,
55
56
  ssl: options[:ssl]
56
57
  }
@@ -12,7 +12,7 @@ module Pact
12
12
  end
13
13
 
14
14
  def to_s
15
- "An interaction with same description (#{new_interaction.description.inspect}) and provider state (#{new_interaction.provider_state.inspect}) but a different #{differences} has already been used. Please use a different description or provider state."
15
+ "An interaction with same description (#{new_interaction.description.inspect}) and provider state (#{new_interaction.provider_state.inspect}) but a different #{differences} has already been used. Please use a different description or provider state, or hard-code any random data."
16
16
  end
17
17
 
18
18
  private
@@ -48,6 +48,7 @@ module Pact
48
48
  def service_options
49
49
  service_options = {
50
50
  pact_dir: options[:pact_dir],
51
+ unique_pact_file_names: options[:unique_pact_file_names],
51
52
  consumer: options[:consumer],
52
53
  provider: options[:provider],
53
54
  cors_enabled: options[:cors],
@@ -20,6 +20,7 @@ module Pact
20
20
  @verified_interactions = Interactions::VerifiedInteractions.new
21
21
  @consumer_contract_details = {
22
22
  pact_dir: options[:pact_dir],
23
+ unique_pact_file_names: options[:unique_pact_file_names],
23
24
  consumer: {name: options[:consumer]},
24
25
  provider: {name: options[:provider]},
25
26
  interactions: verified_interactions,
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module MockService
3
- VERSION = "2.1.1-alpha.2"
3
+ VERSION = "2.2.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.1.1.pre.alpha.2
4
+ version: 2.2.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: 2017-07-28 00:00:00.000000000 Z
15
+ date: 2017-09-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -132,14 +132,14 @@ dependencies:
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '1.0'
135
+ version: '1.2'
136
136
  type: :runtime
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: '1.0'
142
+ version: '1.2'
143
143
  - !ruby/object:Gem::Dependency
144
144
  name: rake
145
145
  requirement: !ruby/object:Gem::Requirement
@@ -302,7 +302,6 @@ files:
302
302
  - lib/pact/mock_service/interactions/verification.rb
303
303
  - lib/pact/mock_service/interactions/verified_interactions.rb
304
304
  - lib/pact/mock_service/logger.rb
305
- - lib/pact/mock_service/os.rb
306
305
  - lib/pact/mock_service/request_decorator.rb
307
306
  - lib/pact/mock_service/request_handlers.rb
308
307
  - lib/pact/mock_service/request_handlers/base_administration_request_handler.rb
@@ -323,7 +322,6 @@ files:
323
322
  - lib/pact/mock_service/server/respawn.rb
324
323
  - lib/pact/mock_service/server/spawn.rb
325
324
  - lib/pact/mock_service/server/wait_for_server_up.rb
326
- - lib/pact/mock_service/server/windows_safe_spawn.rb
327
325
  - lib/pact/mock_service/session.rb
328
326
  - lib/pact/mock_service/spawn.rb
329
327
  - lib/pact/mock_service/version.rb
@@ -342,9 +340,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
342
340
  version: '2.0'
343
341
  required_rubygems_version: !ruby/object:Gem::Requirement
344
342
  requirements:
345
- - - ">"
343
+ - - ">="
346
344
  - !ruby/object:Gem::Version
347
- version: 1.3.1
345
+ version: '0'
348
346
  requirements: []
349
347
  rubyforge_project:
350
348
  rubygems_version: 2.6.12
@@ -1,13 +0,0 @@
1
- module Pact
2
- module MockService
3
- module OS
4
-
5
- extend self
6
-
7
- # Thanks RSpec
8
- def windows?
9
- !!(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
10
- end
11
- end
12
- end
13
- end
@@ -1,44 +0,0 @@
1
- require 'pact/mock_service/server/wait_for_server_up'
2
- require 'pact/mock_service/os'
3
-
4
- module Pact
5
- module MockService
6
- module Server
7
- class WindowsSafeSpawn
8
-
9
- class PortUnavailableError < StandardError; end
10
-
11
- def self.call command, pidfile, port, ssl = false
12
- if pidfile.can_start?
13
- if port_available? port
14
- pid = spawn(command, spawn_options)
15
- pidfile.pid = pid
16
- Process.detach(pid)
17
- Server::WaitForServerUp.(port, {ssl: ssl})
18
- pidfile.write
19
- else
20
- raise PortUnavailableError.new("ERROR: Port #{port} already in use.")
21
- end
22
- end
23
- end
24
-
25
- def self.spawn_options
26
- if Pact::MockService::OS.windows?
27
- {new_pgroup: true}
28
- else
29
- {}
30
- end
31
- end
32
-
33
- def self.port_available? port
34
- server = TCPServer.new('127.0.0.1', port)
35
- true
36
- rescue
37
- false
38
- ensure
39
- server.close if server
40
- end
41
- end
42
- end
43
- end
44
- end