wiremock_mapper 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +0 -1
- data/Rakefile +1 -1
- data/lib/configuration.rb +8 -1
- data/lib/wiremock_mapper.rb +12 -4
- data/spec/configuration_spec.rb +7 -0
- data/spec/wiremock_mapper_spec.rb +79 -0
- data/wiremock_mapper.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8b8dde11f7b190ebf968785989ed808421d8856
|
4
|
+
data.tar.gz: '08a392c0088c3190258fd8894e06a6301a603e35'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ad4b6f724bb95ff9af529bb39c371ba1bf1a613ebeba7f7ee83aa07af3b5d6fbe2105d3aff875075a802b8add0a13a77b2295ce05e5a4927a2aba2d2e54c54
|
7
|
+
data.tar.gz: 76b57620e1af66676ab01f67e0b7f2a516656e50fe12e863dfcfac8f69faac647ab84a368a100f91c0797f6be9cc69561b346097465685f50772cf32bae04e9b
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/lib/configuration.rb
CHANGED
@@ -5,13 +5,14 @@ require_relative 'builders/scenario_builder'
|
|
5
5
|
module WireMockMapper
|
6
6
|
class Configuration
|
7
7
|
@wiremock_url = ''
|
8
|
+
@wiremock_headers = {}
|
8
9
|
|
9
10
|
@request_builder = Builders::RequestBuilder.new
|
10
11
|
@response_builder = Builders::ResponseBuilder.new
|
11
12
|
@scenario_builder = Builders::ScenarioBuilder.new
|
12
13
|
|
13
14
|
class << self
|
14
|
-
attr_reader :request_builder, :response_builder, :wiremock_url, :scenario_builder
|
15
|
+
attr_reader :request_builder, :response_builder, :wiremock_url, :wiremock_headers, :scenario_builder
|
15
16
|
|
16
17
|
# Add mappings to include for all future mappings
|
17
18
|
def create_global_mapping
|
@@ -29,6 +30,12 @@ module WireMockMapper
|
|
29
30
|
def set_wiremock_url(url)
|
30
31
|
@wiremock_url = url
|
31
32
|
end
|
33
|
+
|
34
|
+
# Set the WireMock headers
|
35
|
+
# @param headers [hash] all the header that we need to set for wiremock
|
36
|
+
def set_wiremock_headers(headers)
|
37
|
+
@wiremock_headers = headers
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
34
41
|
end
|
data/lib/wiremock_mapper.rb
CHANGED
@@ -40,6 +40,10 @@ module WireMockMapper
|
|
40
40
|
WIREMOCK_CLEAR_MAPPINGS_PATH = "#{WIREMOCK_MAPPINGS_PATH}/reset".freeze
|
41
41
|
WIREMOCK_RESET_SCENARIOS_PATH = '__admin/scenarios/reset'.freeze
|
42
42
|
|
43
|
+
def headers
|
44
|
+
{ 'Content-Type' => 'application/json' }.merge(Configuration.wiremock_headers)
|
45
|
+
end
|
46
|
+
|
43
47
|
def deep_clone(object)
|
44
48
|
Marshal.load(Marshal.dump(object))
|
45
49
|
end
|
@@ -47,21 +51,24 @@ module WireMockMapper
|
|
47
51
|
def clear_wiremock_mappings(url)
|
48
52
|
uri = URI([url, WIREMOCK_CLEAR_MAPPINGS_PATH].join('/'))
|
49
53
|
http = Net::HTTP.new(uri.host, uri.port)
|
50
|
-
|
54
|
+
http.use_ssl = true if uri.port == 443
|
55
|
+
request = Net::HTTP::Post.new(uri.path, headers)
|
51
56
|
http.request(request)
|
52
57
|
end
|
53
58
|
|
54
59
|
def delete_from_wiremock(url, mapping_id)
|
55
60
|
uri = URI([url, WIREMOCK_MAPPINGS_PATH, mapping_id].join('/'))
|
56
61
|
http = Net::HTTP.new(uri.host, uri.port)
|
57
|
-
|
62
|
+
http.use_ssl = true if uri.port == 443
|
63
|
+
request = Net::HTTP::Delete.new(uri.path, headers)
|
58
64
|
http.request(request)
|
59
65
|
end
|
60
66
|
|
61
67
|
def send_to_wiremock(url, body)
|
62
68
|
uri = URI([url, WIREMOCK_MAPPINGS_PATH].join('/'))
|
63
69
|
http = Net::HTTP.new(uri.host, uri.port)
|
64
|
-
|
70
|
+
http.use_ssl = true if uri.port == 443
|
71
|
+
request = Net::HTTP::Post.new(uri.path, headers)
|
65
72
|
request.body = body.to_json
|
66
73
|
http.request(request)
|
67
74
|
end
|
@@ -69,7 +76,8 @@ module WireMockMapper
|
|
69
76
|
def reset_wiremock_scenarios(url)
|
70
77
|
uri = URI([url, WIREMOCK_RESET_SCENARIOS_PATH].join('/'))
|
71
78
|
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
-
|
79
|
+
http.use_ssl = true if uri.port == 443
|
80
|
+
request = Net::HTTP::Post.new(uri.path, headers)
|
73
81
|
http.request(request)
|
74
82
|
end
|
75
83
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -24,4 +24,11 @@ describe WireMockMapper::Configuration do
|
|
24
24
|
expect(WireMockMapper::Configuration.wiremock_url).to eq('http://whereever.com')
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
describe 'wiremock_headers' do
|
29
|
+
it 'sets the wiremock headers' do
|
30
|
+
WireMockMapper::Configuration.set_wiremock_headers({ 'Authorization' => 'Bearer ABC123' })
|
31
|
+
expect(WireMockMapper::Configuration.wiremock_headers).to eq({ 'Authorization' => 'Bearer ABC123' })
|
32
|
+
end
|
33
|
+
end
|
27
34
|
end
|
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe WireMockMapper do
|
4
4
|
before(:each) do
|
5
5
|
WireMockMapper::Configuration.reset_global_mappings
|
6
|
+
WireMockMapper::Configuration.set_wiremock_headers({})
|
6
7
|
end
|
7
8
|
|
8
9
|
describe 'create_mapping' do
|
@@ -31,6 +32,37 @@ describe WireMockMapper do
|
|
31
32
|
expect(stub).to have_been_requested
|
32
33
|
end
|
33
34
|
|
35
|
+
it 'posts custom header to the wiremock url' do
|
36
|
+
url = 'http://nowhere.com'
|
37
|
+
expected_request_body = { request: { 'method' => 'POST',
|
38
|
+
'url' => '/some/url',
|
39
|
+
'headers' => { 'some_global_header' => { 'equalTo' => 'global value' },
|
40
|
+
'some_header' => { 'equalTo' => 'some header value' } },
|
41
|
+
'bodyPatterns' => [
|
42
|
+
{ 'matches' => 'some request body' }
|
43
|
+
] },
|
44
|
+
response: { 'body' => 'some response body' } }
|
45
|
+
|
46
|
+
stub = stub_request(:post, "#{url}/__admin/mappings").with(body: expected_request_body)
|
47
|
+
.to_return(body: { id: 'whatevs' }.to_json)
|
48
|
+
|
49
|
+
WireMockMapper::Configuration.create_global_mapping do |request|
|
50
|
+
request.with_header('some_global_header').equal_to('global value')
|
51
|
+
end
|
52
|
+
|
53
|
+
WireMockMapper::Configuration.set_wiremock_headers({ 'header1' => 'header-value1' })
|
54
|
+
|
55
|
+
WireMockMapper.create_mapping(url) do |request, respond|
|
56
|
+
request.is_a_post
|
57
|
+
.with_url.equal_to('/some/url')
|
58
|
+
.with_header('some_header').equal_to('some header value')
|
59
|
+
.with_body.matching('some request body')
|
60
|
+
respond.with_body('some response body')
|
61
|
+
end
|
62
|
+
|
63
|
+
expect(stub).to have_requested(:post, "#{url}/__admin/mappings").with(headers: { 'header1' => 'header-value1' })
|
64
|
+
end
|
65
|
+
|
34
66
|
it 'posts the correct json with configured global mappings to the wiremock url' do
|
35
67
|
url = 'http://nowhere.com'
|
36
68
|
expected_request_body = { request: { 'method' => 'POST',
|
@@ -129,6 +161,19 @@ describe WireMockMapper do
|
|
129
161
|
|
130
162
|
expect(stub).to have_been_requested
|
131
163
|
end
|
164
|
+
|
165
|
+
it 'issues a DELETE with custom headers for the supplied mapping id' do
|
166
|
+
mapping_id = 'james-james-james'
|
167
|
+
url = 'http://nowhere.com'
|
168
|
+
stub = stub_request(:delete, "#{url}/__admin/mappings/#{mapping_id}")
|
169
|
+
|
170
|
+
WireMockMapper::Configuration.set_wiremock_headers({ 'header2' => 'header-value2' })
|
171
|
+
|
172
|
+
WireMockMapper.delete_mapping(mapping_id, url)
|
173
|
+
|
174
|
+
expect(stub).to have_requested(:delete, "#{url}/__admin/mappings/#{mapping_id}")
|
175
|
+
.with(headers: { 'header2' => 'header-value2' })
|
176
|
+
end
|
132
177
|
end
|
133
178
|
|
134
179
|
describe 'clear_mappings' do
|
@@ -139,5 +184,39 @@ describe WireMockMapper do
|
|
139
184
|
|
140
185
|
expect(stub).to have_been_requested
|
141
186
|
end
|
187
|
+
|
188
|
+
it 'POSTS with custom headers to the wiremock __admin/mappings/reset path' do
|
189
|
+
url = 'http://nowhere.com'
|
190
|
+
stub = stub_request(:post, "#{url}/__admin/mappings/reset")
|
191
|
+
|
192
|
+
WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
|
193
|
+
|
194
|
+
WireMockMapper.clear_mappings(url)
|
195
|
+
|
196
|
+
expect(stub).to have_requested(:post,
|
197
|
+
"#{url}/__admin/mappings/reset").with(headers: { 'header3' => 'header-value3' })
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe 'reset_scenarios' do
|
202
|
+
it 'POSTS to the wiremock __admin/scenarios/reset path' do
|
203
|
+
url = 'http://nowhere.com'
|
204
|
+
stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
|
205
|
+
WireMockMapper.reset_scenarios(url)
|
206
|
+
|
207
|
+
expect(stub).to have_been_requested
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'POSTS with custom headers to the wiremock __admin/scenarios/reset path' do
|
211
|
+
url = 'http://nowhere.com'
|
212
|
+
stub = stub_request(:post, "#{url}/__admin/scenarios/reset")
|
213
|
+
|
214
|
+
WireMockMapper::Configuration.set_wiremock_headers({ 'header3' => 'header-value3' })
|
215
|
+
|
216
|
+
WireMockMapper.reset_scenarios(url)
|
217
|
+
|
218
|
+
expect(stub).to have_requested(:post,
|
219
|
+
"#{url}/__admin/scenarios/reset").with(headers: { 'header3' => 'header-value3' })
|
220
|
+
end
|
142
221
|
end
|
143
222
|
end
|
data/wiremock_mapper.gemspec
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.expand_path('
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('lib', __dir__))
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'wiremock_mapper'
|
5
|
-
spec.version = '
|
5
|
+
spec.version = '3.0.0'
|
6
6
|
spec.platform = Gem::Platform::RUBY
|
7
7
|
spec.required_ruby_version = '>= 2.0.0'
|
8
8
|
spec.authors = ['Isaac Datlof']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiremock_mapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Datlof
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codeclimate-test-reporter
|
@@ -173,7 +173,7 @@ homepage: http://github.com/ike18t/wiremock_mapper
|
|
173
173
|
licenses:
|
174
174
|
- MIT
|
175
175
|
metadata: {}
|
176
|
-
post_install_message:
|
176
|
+
post_install_message:
|
177
177
|
rdoc_options: []
|
178
178
|
require_paths:
|
179
179
|
- lib
|
@@ -188,9 +188,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
- !ruby/object:Gem::Version
|
189
189
|
version: '0'
|
190
190
|
requirements: []
|
191
|
-
rubyforge_project:
|
191
|
+
rubyforge_project:
|
192
192
|
rubygems_version: 2.6.8
|
193
|
-
signing_key:
|
193
|
+
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Ruby DSL for setting up WireMock mappings
|
196
196
|
test_files:
|