pact-mock_service 2.1.0 → 2.1.1.pre.alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +13 -13
- data/lib/pact/mock_service/cli.rb +30 -3
- data/lib/pact/mock_service/cli/pidfile.rb +16 -3
- data/lib/pact/mock_service/os.rb +13 -0
- data/lib/pact/mock_service/server/windows_safe_spawn.rb +44 -0
- data/lib/pact/mock_service/version.rb +1 -1
- metadata +41 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5693645528ece7ef91958e2598f64bba38215104
|
4
|
+
data.tar.gz: 3a57c015eb730e45150a23a0b63b818461e61cbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64fe9e5ed774d2bef6f2a2b8746b5dbb9f6e46ff586ebc37957c0bd9719444b31972dbb5aaf43b52046b85752bd0d2cc628102233d486387a97d07d26a362f1
|
7
|
+
data.tar.gz: 9713fb5b520bcff76a6e45aafb88dd17835e311a907e88288f4a3b6502c702a287af7cf6acb9af8b7f670371e8000f33aaed214db7d57555bf753bfa79936046
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Pact Mock Service
|
2
2
|
|
3
|
-
[](https://travis-ci.org/pact-foundation/pact-mock_service)
|
4
4
|
|
5
|
-
This codebase provides the mock service used by implementations of [Pact][pact]. It is packaged as a gem, and as a standalone executable for Mac OSX and Linux
|
5
|
+
This codebase provides the mock service used by implementations of [Pact][pact]. It is packaged as a gem, and as a standalone executable for Mac OSX and Linux and Windows.
|
6
6
|
|
7
7
|
The mock service provides the following endpoints:
|
8
8
|
|
@@ -11,12 +11,20 @@ The mock service provides the following endpoints:
|
|
11
11
|
* GET /interactions/verification - determine whether the expected interactions have taken place
|
12
12
|
* POST /pact - write the pact file
|
13
13
|
|
14
|
-
As the Pact mock service can be used as a standalone executable and administered via HTTP, it can be used for testing with any language. All that is required is a library in the native language to create the HTTP calls listed above.
|
14
|
+
As the Pact mock service can be used as a standalone executable and administered via HTTP, it can be used for testing with any language. All that is required is a library in the native language to create the HTTP calls listed above. Check out [docs.pact.io](https://docs.pact.io) for a list of implemented languages. If you are interested in creating bindings in a new langauge, and have a chat to one of us on the [pact-dev Google group][pact-dev].
|
15
|
+
|
16
|
+
## Documentation
|
17
|
+
|
18
|
+
You can find documentation for the mock service in the repository [wiki][wiki].
|
15
19
|
|
16
20
|
## Usage
|
17
21
|
|
18
22
|
For some examples of the HTTP requests that occur under the hood when using either the Ruby client or the Javascript client, see this [gist](https://gist.github.com/bethesque/9d81f21d6f77650811f4).
|
19
23
|
|
24
|
+
### Mac OSX, Linux and Windows, without Ruby
|
25
|
+
|
26
|
+
See the [releases][releases] page for the latest standalone executables.
|
27
|
+
|
20
28
|
### With Ruby on Mac OSX and Linux
|
21
29
|
|
22
30
|
$ gem install pact-mock_service
|
@@ -38,22 +46,14 @@ If you need to provide your own certificate and key, use the following syntax.
|
|
38
46
|
|
39
47
|
$ pact-mock-service --port 1234 --ssl --sslcert PATH_TO_CERT --sslkey PATH_TO_KEY
|
40
48
|
|
41
|
-
### Mac OSX and Linux, without Ruby
|
42
|
-
|
43
|
-
See the [releases][releases] page for the latest standalone executables.
|
44
|
-
|
45
|
-
### Windows, without Ruby
|
46
|
-
|
47
|
-
See the [releases][releases] page for the latest standalone executables.
|
48
|
-
|
49
49
|
## Contributing
|
50
50
|
|
51
51
|
See [CONTRIBUTING.md](/CONTRIBUTING.md)
|
52
52
|
|
53
53
|
[pact]: https://github.com/realestate-com-au/pact
|
54
|
-
[releases]: https://github.com/
|
54
|
+
[releases]: https://github.com/pact-foundation/pact-mock_service/releases
|
55
55
|
[javascript]: https://github.com/DiUS/pact-consumer-js-dsl
|
56
56
|
[pact-dev]: https://groups.google.com/forum/#!forum/pact-dev
|
57
|
-
[windows]: https://github.com/bethesque/pact-mock_service/wiki/Building-a-Windows-standalone-executable
|
58
57
|
[install-windows]: https://github.com/bethesque/pact-mock_service/wiki/Installing-the-pact-mock_service-gem-on-Windows
|
59
58
|
[why-generated]: https://github.com/realestate-com-au/pact/wiki/FAQ#why-are-the-pacts-generated-and-not-static
|
59
|
+
[wiki]: https://github.com/pact-foundation/pact-mock_service/wiki
|
@@ -5,6 +5,7 @@ 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'
|
8
9
|
|
9
10
|
module Pact
|
10
11
|
module MockService
|
@@ -59,9 +60,7 @@ module Pact
|
|
59
60
|
method_option :pid_dir, desc: "PID dir", default: 'tmp/pids'
|
60
61
|
|
61
62
|
def start
|
62
|
-
|
63
|
-
service
|
64
|
-
end
|
63
|
+
spawn_mock_service
|
65
64
|
end
|
66
65
|
|
67
66
|
desc 'stop', "Stop a Pact mock service"
|
@@ -174,6 +173,34 @@ module Pact
|
|
174
173
|
yield
|
175
174
|
end
|
176
175
|
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
|
177
204
|
end
|
178
205
|
end
|
179
206
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'pact/mock_service/os'
|
2
3
|
|
3
4
|
module Pact
|
4
5
|
module MockService
|
@@ -73,14 +74,13 @@ module Pact
|
|
73
74
|
sleep sleep_time
|
74
75
|
tries += 1
|
75
76
|
end
|
76
|
-
raise "Process #{pid_from_file} not stopped after {100 * sleep_time} seconds." if process_running?
|
77
|
+
raise "Process #{pid_from_file} not stopped after #{100 * sleep_time} seconds." if process_running?
|
77
78
|
end
|
78
79
|
|
79
80
|
def kill_process
|
80
81
|
if file_exists?
|
81
82
|
begin
|
82
|
-
|
83
|
-
Process.kill 2, pid_from_file
|
83
|
+
windows? ? windows_kill : kill_2
|
84
84
|
waitpid
|
85
85
|
delete
|
86
86
|
rescue Errno::ESRCH
|
@@ -91,6 +91,19 @@ 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
|
94
107
|
end
|
95
108
|
end
|
96
109
|
end
|
@@ -0,0 +1,44 @@
|
|
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
|
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.
|
4
|
+
version: 2.1.1.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Fraser
|
@@ -12,22 +12,22 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-
|
15
|
+
date: 2017-07-28 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rack
|
19
19
|
requirement: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - "~>"
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: '0'
|
23
|
+
version: '2.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - "
|
28
|
+
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '0'
|
30
|
+
version: '2.0'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: rspec
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,16 +74,16 @@ dependencies:
|
|
74
74
|
name: thor
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- - "
|
77
|
+
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '0'
|
79
|
+
version: '0.19'
|
80
80
|
type: :runtime
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - "
|
84
|
+
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '0'
|
86
|
+
version: '0.19'
|
87
87
|
- !ruby/object:Gem::Dependency
|
88
88
|
name: json
|
89
89
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,16 +102,16 @@ dependencies:
|
|
102
102
|
name: webrick
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- - "
|
105
|
+
- - "~>"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: '
|
107
|
+
version: '1.3'
|
108
108
|
type: :runtime
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- - "
|
112
|
+
- - "~>"
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
114
|
+
version: '1.3'
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: term-ansicolor
|
117
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -214,30 +214,44 @@ dependencies:
|
|
214
214
|
name: activesupport
|
215
215
|
requirement: !ruby/object:Gem::Requirement
|
216
216
|
requirements:
|
217
|
-
- - "
|
217
|
+
- - "~>"
|
218
218
|
- !ruby/object:Gem::Version
|
219
|
-
version: '
|
219
|
+
version: '5.1'
|
220
220
|
type: :development
|
221
221
|
prerelease: false
|
222
222
|
version_requirements: !ruby/object:Gem::Requirement
|
223
223
|
requirements:
|
224
|
-
- - "
|
224
|
+
- - "~>"
|
225
225
|
- !ruby/object:Gem::Version
|
226
|
-
version: '
|
226
|
+
version: '5.1'
|
227
227
|
- !ruby/object:Gem::Dependency
|
228
228
|
name: faraday
|
229
229
|
requirement: !ruby/object:Gem::Requirement
|
230
230
|
requirements:
|
231
|
-
- - "
|
231
|
+
- - "~>"
|
232
232
|
- !ruby/object:Gem::Version
|
233
|
-
version: '0'
|
233
|
+
version: '0.12'
|
234
234
|
type: :development
|
235
235
|
prerelease: false
|
236
236
|
version_requirements: !ruby/object:Gem::Requirement
|
237
237
|
requirements:
|
238
|
-
- - "
|
238
|
+
- - "~>"
|
239
239
|
- !ruby/object:Gem::Version
|
240
|
-
version: '0'
|
240
|
+
version: '0.12'
|
241
|
+
- !ruby/object:Gem::Dependency
|
242
|
+
name: octokit
|
243
|
+
requirement: !ruby/object:Gem::Requirement
|
244
|
+
requirements:
|
245
|
+
- - "~>"
|
246
|
+
- !ruby/object:Gem::Version
|
247
|
+
version: '4.7'
|
248
|
+
type: :development
|
249
|
+
prerelease: false
|
250
|
+
version_requirements: !ruby/object:Gem::Requirement
|
251
|
+
requirements:
|
252
|
+
- - "~>"
|
253
|
+
- !ruby/object:Gem::Version
|
254
|
+
version: '4.7'
|
241
255
|
description:
|
242
256
|
email:
|
243
257
|
- james.fraser@alumni.swinburne.edu
|
@@ -288,6 +302,7 @@ files:
|
|
288
302
|
- lib/pact/mock_service/interactions/verification.rb
|
289
303
|
- lib/pact/mock_service/interactions/verified_interactions.rb
|
290
304
|
- lib/pact/mock_service/logger.rb
|
305
|
+
- lib/pact/mock_service/os.rb
|
291
306
|
- lib/pact/mock_service/request_decorator.rb
|
292
307
|
- lib/pact/mock_service/request_handlers.rb
|
293
308
|
- lib/pact/mock_service/request_handlers/base_administration_request_handler.rb
|
@@ -308,6 +323,7 @@ files:
|
|
308
323
|
- lib/pact/mock_service/server/respawn.rb
|
309
324
|
- lib/pact/mock_service/server/spawn.rb
|
310
325
|
- lib/pact/mock_service/server/wait_for_server_up.rb
|
326
|
+
- lib/pact/mock_service/server/windows_safe_spawn.rb
|
311
327
|
- lib/pact/mock_service/session.rb
|
312
328
|
- lib/pact/mock_service/spawn.rb
|
313
329
|
- lib/pact/mock_service/version.rb
|
@@ -326,12 +342,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
326
342
|
version: '2.0'
|
327
343
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
328
344
|
requirements:
|
329
|
-
- - "
|
345
|
+
- - ">"
|
330
346
|
- !ruby/object:Gem::Version
|
331
|
-
version:
|
347
|
+
version: 1.3.1
|
332
348
|
requirements: []
|
333
349
|
rubyforge_project:
|
334
|
-
rubygems_version: 2.
|
350
|
+
rubygems_version: 2.6.12
|
335
351
|
signing_key:
|
336
352
|
specification_version: 4
|
337
353
|
summary: Provides a mock service for use with Pact
|