pact-provider-proxy 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +4 -0
- data/lib/pact/provider/proxy.rb +9 -0
- data/lib/pact/provider/proxy/configure_service_provider.rb +22 -0
- data/lib/pact/provider/proxy/pact_helper.rb +1 -0
- data/lib/pact/provider/proxy/tasks.rb +1 -0
- data/lib/pact/provider/proxy/tasks/proxy_verification_task.rb +57 -0
- data/lib/pact/provider/proxy/version.rb +7 -0
- data/pact-provider-proxy.gemspec +25 -0
- data/spec/support/pact.json +18 -0
- data/spec/support/pact_helper.rb +7 -0
- data/spec/tasks.rake +21 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
M2E2ZmE4NTgyMjYyMDMyZTA2ZGQ4YzFkYzMxYWY0MDBhMmI5ZGQxNQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzEwOWRiYTc3ZWE3MDJiZTY1YTliNjdmNDVjYTc2NDQ0M2I1M2M3Zg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzQ1MjUyYzFjZGIyODhlYTk4Nzk3NGE4MjYxMmYxMTcwOWE3MjJhMjYzMWIx
|
10
|
+
MzZmOGI3Mzg4OGNmMWZmMThiNDY3ZmQ1MjUzZjhlZWM3MDkzYjkwZmQwYTg1
|
11
|
+
OWYxMmQ4ZGU0M2M1ZDM3YzIyZDRkMDA5YjI0ZjdjN2U0ODE1ZDU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmNjYTNjOGQ2NTE2NmE0MzAwMTdhY2ExMWYyNmYxNzM4MThlMzAwMmFiYmNj
|
14
|
+
MmU3MGQyZDY4NTA1NTQ0MmU1NTZlMzk1NmU5MjNmYTJmY2NiM2VlZjI1MDI3
|
15
|
+
OGE4NGUzZTlmMGE0ZTNjMzFkNzUwOGQ1YTAwZTFhZWVlN2NmMzg=
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Beth
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Pact::Proxy
|
2
|
+
|
3
|
+
Allows pact verification against a running provider at a configurable base URL (normal pact verification is run against a code base using Rack::Test::Methods - no process is actually spawned).
|
4
|
+
|
5
|
+
This allows testing against providers where you have access to a running instance of a provider, but you do not have access to its code base, or where the provider is not a ruby application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'pact-proxy'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pact-proxy
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Usually, you would configure and run pact:verify in the provider code base.
|
24
|
+
If you are using a pact-proxy to run your pact verify task, it is probably because you don't have access to the code base of the provider project, or it is not a ruby project, so it may make sense to include this task in your consumer project.
|
25
|
+
|
26
|
+
Specifying a pact_helper is optional, and is only required if you are using provider states.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'pact/provider/proxy/tasks'
|
30
|
+
|
31
|
+
Pact::ProxyVerificationTask.new :monolith do | task |
|
32
|
+
task.pact_url './spec/pacts/my-consumer_my-monolith.json', :pact_helper => './spec/support/monolith_pact_helper'
|
33
|
+
task.provider_base_url 'http://my-monolith'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
Then run:
|
38
|
+
|
39
|
+
$ rake pact:verify:monolith
|
40
|
+
|
41
|
+
If you have access to your provider code base, and are able to spawn an instance locally, you could add some rake tasks to start and stop your server. (Please note, I have actually run this code, I just think it should work...)
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
|
45
|
+
Pact::ProxyVerificationTask.new :running_local_monolith do | task |
|
46
|
+
task.pact_url './spec/pacts/my-consumer_my-local-monolith.json'
|
47
|
+
task.provider_base_url 'http://localhost:8080'
|
48
|
+
end
|
49
|
+
|
50
|
+
task :start_provider do
|
51
|
+
system "./provider_start -p 8080"
|
52
|
+
end
|
53
|
+
|
54
|
+
task :stop_provider do
|
55
|
+
system "./provider_stop"
|
56
|
+
end
|
57
|
+
|
58
|
+
task 'pact:verify:local_monolith' do
|
59
|
+
begin
|
60
|
+
Rake::Task['start_provider'].execute
|
61
|
+
Rake::Task['pact:verify:running_local_monolith'].execute
|
62
|
+
ensure
|
63
|
+
Rake::Task['stop_provider'].execute
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
If a ruby adapter to the underlying datastore cannot be used to set up provider states, shell scripts that invoke code in the native language might work. If you have access to the code base, another alternative could be to provide an endpoint on your app that sets up data inside itself, that is only mounted in test mode. eg 'http://localhost:8080/setUpProviderState?name=a%20thing%20exists' and 'http://localhost:8080/tearDownProviderState?name=a%20thing%20exists'
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pact/provider/rspec'
|
2
|
+
require 'rack/reverse_proxy'
|
3
|
+
|
4
|
+
module Pact
|
5
|
+
module Proxy
|
6
|
+
|
7
|
+
class ConfigureServiceProvider
|
8
|
+
|
9
|
+
def self.call provider_base_url
|
10
|
+
|
11
|
+
Pact.service_provider "Running Provider Application" do
|
12
|
+
app do
|
13
|
+
Rack::ReverseProxy.new do
|
14
|
+
reverse_proxy '/', provider_base_url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# No op
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'pact/provider/proxy/tasks/proxy_verification_task'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
require 'pact/tasks/task_helper'
|
3
|
+
|
4
|
+
module Pact
|
5
|
+
class ProxyVerificationTask < ::Rake::TaskLib
|
6
|
+
|
7
|
+
include Pact::TaskHelper
|
8
|
+
|
9
|
+
attr_reader :pact_spec_configs
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@pact_spec_configs = []
|
13
|
+
@provider_base_url = nil
|
14
|
+
@name = name
|
15
|
+
yield self
|
16
|
+
rake_task
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def pact_url(uri, options = {})
|
21
|
+
@pact_spec_configs << {uri: uri, pact_helper: options.fetch(:pact_helper, pact_helper_url)}
|
22
|
+
end
|
23
|
+
|
24
|
+
# For compatiblity with the normal VerificationTask, allow task.uri
|
25
|
+
alias_method :uri, :pact_url
|
26
|
+
|
27
|
+
def provider_base_url url
|
28
|
+
@provider_base_url = url
|
29
|
+
end
|
30
|
+
|
31
|
+
def pact_helper_url
|
32
|
+
File.expand_path('../../../pact_helper', __FILE__)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
attr_reader :name
|
38
|
+
|
39
|
+
def rake_task
|
40
|
+
namespace :pact do
|
41
|
+
desc "Verify provider against the consumer pacts for #{name}"
|
42
|
+
task "verify:#{name}", :description, :provider_state do |t, args|
|
43
|
+
|
44
|
+
require 'pact/provider/pact_spec_runner'
|
45
|
+
require 'pact/provider/proxy/configure_service_provider'
|
46
|
+
|
47
|
+
Pact::Proxy::ConfigureServiceProvider.call @provider_base_url
|
48
|
+
options = {criteria: spec_criteria(args)}
|
49
|
+
|
50
|
+
handle_verification_failure do
|
51
|
+
Provider::PactSpecRunner.new(@pact_spec_configs, options).run
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pact/provider/proxy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "pact-provider-proxy"
|
8
|
+
spec.version = Pact::Provider::Proxy::VERSION
|
9
|
+
spec.authors = ["Beth"]
|
10
|
+
spec.email = ["beth@bethesque.com"]
|
11
|
+
spec.description = %q{See summary}
|
12
|
+
spec.summary = %q{Allows verification of a pact against a running provider}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rack-reverse-proxy"
|
22
|
+
spec.add_dependency "pact"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"consumer" : { "name": "a consumer"},
|
3
|
+
"provider" : { "name": "a running provider"},
|
4
|
+
"interactions": [
|
5
|
+
{
|
6
|
+
"description": "a request for the index",
|
7
|
+
"provider_state": "some state",
|
8
|
+
"request" : {
|
9
|
+
"method" : "get", "path": "/"
|
10
|
+
},
|
11
|
+
"response": {
|
12
|
+
"status" : 200,
|
13
|
+
"body": "Monolith!"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
]
|
18
|
+
}
|
data/spec/tasks.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'pact/provider/proxy/tasks'
|
2
|
+
|
3
|
+
Pact::ProxyVerificationTask.new :monolith do | task |
|
4
|
+
task.pact_url './spec/support/pact.json', :pact_helper => './spec/support/pact_helper'
|
5
|
+
task.provider_base_url 'http://localhost:9292'
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :pact do
|
9
|
+
namespace :test do
|
10
|
+
task :spawn_test_monolith do
|
11
|
+
require 'pact/consumer/app_manager'
|
12
|
+
Pact::Consumer::AppManager.instance.register lambda { | env | [200, {}, ["Monolith!"]] }, 9292
|
13
|
+
Pact::Consumer::AppManager.instance.spawn_all
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task 'pact:verify:monolith' => 'pact:test:spawn_test_monolith'
|
19
|
+
|
20
|
+
task :spec => ['pact:verify:monolith']
|
21
|
+
task :default => [:spec]
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pact-provider-proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Beth
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack-reverse-proxy
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pact
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: See summary
|
70
|
+
email:
|
71
|
+
- beth@bethesque.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- CHANGELOG.md
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/pact/provider/proxy.rb
|
83
|
+
- lib/pact/provider/proxy/configure_service_provider.rb
|
84
|
+
- lib/pact/provider/proxy/pact_helper.rb
|
85
|
+
- lib/pact/provider/proxy/tasks.rb
|
86
|
+
- lib/pact/provider/proxy/tasks/proxy_verification_task.rb
|
87
|
+
- lib/pact/provider/proxy/version.rb
|
88
|
+
- pact-provider-proxy.gemspec
|
89
|
+
- spec/support/pact.json
|
90
|
+
- spec/support/pact_helper.rb
|
91
|
+
- spec/tasks.rake
|
92
|
+
homepage: ''
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.1.11
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Allows verification of a pact against a running provider
|
116
|
+
test_files:
|
117
|
+
- spec/support/pact.json
|
118
|
+
- spec/support/pact_helper.rb
|
119
|
+
- spec/tasks.rake
|