pact-mock_service 2.3.0 → 2.4.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: e7ba885324798c8512e3957562c9c07f903ef605
4
- data.tar.gz: 7c8718131be50169a6a1d8341905b20e25b4e73d
3
+ metadata.gz: 199d51223a496a48e6ab4ca142d1a1c9fdac4a0b
4
+ data.tar.gz: 19d3aa4d3228559d5ceb27e7678d3f27842b0eeb
5
5
  SHA512:
6
- metadata.gz: abbd1c16191e86672a8aac3217836bf98190ff218c84362f99faaa4618e6802327e697b1d9dec1433f05a263f5994ec4c68c4b20ea983e1e4066de8f37b4ff8a
7
- data.tar.gz: d811402182f55a9b91ef04f122f02da0ba5ea7ff0168c57332e2ceac000976b861206812c67fd647ff87f2e20dac5f2f9aade0166322ac0fa4a9e6161cb5b858
6
+ metadata.gz: 3ade3ab0ddb3feb73edcca000b9fa99ba0e82d373859f8accf0b1e4b532ad1b7ecfc48b0ee27a208624da6d1a528099a14ebc277c0afe53a0362a1f2f812f528
7
+ data.tar.gz: a2916297569c675ab1ad635ce883b162fc54f5c030de1e326879b521bd89882576b47a253d836fd5d24e89ba5b3ac230ed730d65e6dda14ee99334c281b7bd3a
data/CHANGELOG.md CHANGED
@@ -2,7 +2,10 @@ 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.3.0 (2017-20-04)
5
+ ### 2.4.0 (2017-10-13)
6
+ * 56bd683 - feat(stub): add pact-stub-service CLI (Beth Skurrie, Fri Oct 13 08:20:49 2017 +1100)
7
+
8
+ ### 2.3.0 (2017-10-04)
6
9
  * 79cbdc9 - feat: add example script showing usage (Beth Skurrie, Wed Oct 4 13:42:06 2017 +1100)
7
10
  * 873d9ee - feat: only write pact on shutdown of mock service if pact has not already been written (Beth Skurrie, Wed Oct 4 13:41:01 2017 +1100)
8
11
  * d3c6067 - feat(cli): add --pact-file-write-mode to cli and remove --unique-pact-file-names (Beth Skurrie, Wed Oct 4 08:01:25 2017 +1100)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pact/stub_service/cli'
3
+ Pact::StubService::CLI.start
@@ -20,6 +20,7 @@ module Pact
20
20
  logger = Logger.from_options(options)
21
21
  @name = options.fetch(:name, "MockService")
22
22
  @session = Session.new(options.merge(logger: logger))
23
+ setup_stub(options[:stub_pactfile_paths]) if options[:stub_pactfile_paths] && options[:stub_pactfile_paths].any?
23
24
  request_handlers = RequestHandlers.new(@name, logger, @session, options)
24
25
  @app = Rack::Builder.app do
25
26
  use Pact::Consumer::MockService::ErrorHandler, logger
@@ -36,6 +37,15 @@ module Pact
36
37
  write_pact_if_configured
37
38
  end
38
39
 
40
+ def setup_stub stub_pactfile_paths
41
+ stub_pactfile_paths.each do | pactfile_path |
42
+ $stdout.puts "Loading interactions from #{pactfile_path}"
43
+ hash_interactions = JSON.parse(File.read(pactfile_path))['interactions']
44
+ interactions = hash_interactions.collect { | hash | Interaction.from_hash(hash) }
45
+ @session.set_expected_interactions interactions
46
+ end
47
+ end
48
+
39
49
  def write_pact_if_configured
40
50
  consumer_contract_writer = ConsumerContractWriter.new(@session.consumer_contract_details, StdoutLogger.new)
41
51
  if consumer_contract_writer.can_write? && !@session.pact_written?
@@ -0,0 +1,71 @@
1
+ require 'thor'
2
+
3
+ module Pact
4
+ module MockService
5
+ class CLI < Thor
6
+ ##
7
+ # Custom Thor task allows the following:
8
+ #
9
+ # `script arg1 arg2` to be interpreted as `script <default_task> arg1 arg2`
10
+ # `--option 1 --option 2` to be interpreted as `--option 1 2` (the standard Thor format for multiple value options)
11
+ # `script --help` to display the help for the default task instead of the command list
12
+ #
13
+ class CustomThor < ::Thor
14
+
15
+ no_commands do
16
+ def self.start given_args = ARGV, config = {}
17
+ super(massage_args(given_args))
18
+ end
19
+
20
+ def help *args
21
+ if args.empty?
22
+ super(self.class.default_task)
23
+ else
24
+ super
25
+ end
26
+ end
27
+
28
+ def self.massage_args argv
29
+ prepend_default_task_name(turn_muliple_tag_options_into_array(argv))
30
+ end
31
+
32
+ def self.prepend_default_task_name argv
33
+ if known_first_arguments.include?(argv[0])
34
+ argv
35
+ else
36
+ [default_command] + argv
37
+ end
38
+ end
39
+
40
+ # other task names, help, and the help shortcuts
41
+ def self.known_first_arguments
42
+ @known_first_arguments ||= tasks.keys + ::Thor::HELP_MAPPINGS + ['help']
43
+ end
44
+
45
+ def self.turn_muliple_tag_options_into_array argv
46
+ new_argv = []
47
+ opt_name = nil
48
+ argv.each_with_index do | arg, i |
49
+ if arg.start_with?('-')
50
+ opt_name = arg
51
+ existing = new_argv.find { | a | a.first == opt_name }
52
+ if !existing
53
+ new_argv << [arg]
54
+ end
55
+ else
56
+ if opt_name
57
+ existing = new_argv.find { | a | a.first == opt_name }
58
+ existing << arg
59
+ opt_name = nil
60
+ else
61
+ new_argv << [arg]
62
+ end
63
+ end
64
+ end
65
+ new_argv.flatten
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,6 +1,7 @@
1
1
  require 'find_a_port'
2
2
  require 'pact/mock_service/app'
3
3
  require 'pact/consumer/mock_service/set_location'
4
+ require 'pact/mock_service/run'
4
5
 
5
6
  module Pact
6
7
  module MockService
@@ -53,7 +54,8 @@ module Pact
53
54
  provider: options[:provider],
54
55
  cors_enabled: options[:cors],
55
56
  pact_specification_version: options[:pact_specification_version],
56
- pactfile_write_mode: options[:pact_file_write_mode]
57
+ pactfile_write_mode: options[:pact_file_write_mode],
58
+ stub_pactfile_paths: options[:stub_pactfile_paths]
57
59
  }
58
60
  service_options[:log_file] = open_log_file if options[:log]
59
61
  service_options
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module MockService
3
- VERSION = "2.3.0"
3
+ VERSION = "2.4.0"
4
4
  end
5
5
  end
@@ -0,0 +1,45 @@
1
+ require 'pact/mock_service/cli/custom_thor'
2
+ require 'webrick/https'
3
+ require 'rack/handler/webrick'
4
+ require 'fileutils'
5
+ require 'pact/mock_service/server/wait_for_server_up'
6
+ require 'pact/mock_service/cli/pidfile'
7
+ require 'socket'
8
+
9
+ module Pact
10
+ module StubService
11
+ class CLI < Pact::MockService::CLI::CustomThor
12
+
13
+ desc 'PACT ...', "Start a stub service with the given pact file(s). Note that this is in beta release, and no logic has been added to handle the situation where more than one matching interaction is found for a request. At the moment, an error response will be returned."
14
+
15
+ method_option :port, aliases: "-p", desc: "Port on which to run the service"
16
+ method_option :host, aliases: "-h", desc: "Host on which to bind the service", default: 'localhost'
17
+ method_option :log, aliases: "-l", desc: "File to which to log output"
18
+ method_option :cors, aliases: "-o", desc: "Support browser security in tests by responding to OPTIONS requests and adding CORS headers to mocked responses"
19
+ method_option :ssl, desc: "Use a self-signed SSL cert to run the service over HTTPS", type: :boolean, default: false
20
+ method_option :sslcert, desc: "Specify the path to the SSL cert to use when running the service over HTTPS"
21
+ method_option :sslkey, desc: "Specify the path to the SSL key to use when running the service over HTTPS"
22
+ method_option :stub_pactfile_paths, hide: true
23
+
24
+ def service(*pactfiles)
25
+ raise Thor::Error.new("Please provide an existing pact file to load") if pactfiles.empty?
26
+ require 'pact/mock_service/run'
27
+ options.stub_pactfile_paths = pactfiles
28
+ opts = Thor::CoreExt::HashWithIndifferentAccess.new
29
+ opts.merge!(options)
30
+ opts[:stub_pactfile_paths] = pactfiles
31
+ opts[:pactfile_write_mode] = 'none'
32
+ MockService::Run.(opts)
33
+ end
34
+
35
+ desc 'version', "Show the pact-stub-service gem version"
36
+
37
+ def version
38
+ require 'pact/mock_service/version.rb'
39
+ puts Pact::MockService::VERSION
40
+ end
41
+
42
+ default_task :service
43
+ end
44
+ end
45
+ 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.3.0
4
+ version: 2.4.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-10-04 00:00:00.000000000 Z
15
+ date: 2017-10-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -281,6 +281,7 @@ email:
281
281
  - beth@bethesque.com
282
282
  executables:
283
283
  - pact-mock-service
284
+ - pact-stub-service
284
285
  extensions: []
285
286
  extra_rdoc_files: []
286
287
  files:
@@ -289,6 +290,7 @@ files:
289
290
  - LICENSE.txt
290
291
  - README.md
291
292
  - bin/pact-mock-service
293
+ - bin/pact-stub-service
292
294
  - lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
293
295
  - lib/pact/consumer/mock_service/error_handler.rb
294
296
  - lib/pact/consumer/mock_service/rack_request_helper.rb
@@ -303,6 +305,7 @@ files:
303
305
  - lib/pact/mock_service/app.rb
304
306
  - lib/pact/mock_service/app_manager.rb
305
307
  - lib/pact/mock_service/cli.rb
308
+ - lib/pact/mock_service/cli/custom_thor.rb
306
309
  - lib/pact/mock_service/cli/pidfile.rb
307
310
  - lib/pact/mock_service/client.rb
308
311
  - lib/pact/mock_service/control_server/app.rb
@@ -346,6 +349,7 @@ files:
346
349
  - lib/pact/mock_service/session.rb
347
350
  - lib/pact/mock_service/spawn.rb
348
351
  - lib/pact/mock_service/version.rb
352
+ - lib/pact/stub_service/cli.rb
349
353
  homepage: https://github.com/bethesque/pact-mock_service
350
354
  licenses:
351
355
  - MIT
@@ -366,7 +370,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
366
370
  version: '0'
367
371
  requirements: []
368
372
  rubyforge_project:
369
- rubygems_version: 2.6.13
373
+ rubygems_version: 2.6.14
370
374
  signing_key:
371
375
  specification_version: 4
372
376
  summary: Provides a mock service for use with Pact