gds-api-adapters 10.17.1 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require_relative 'base'
2
- #require_relative 'exceptions'
3
2
 
4
3
  class GdsApi::Router < GdsApi::Base
5
4
 
@@ -25,20 +24,20 @@ class GdsApi::Router < GdsApi::Base
25
24
 
26
25
  def add_route(path, type, backend_id, options = {})
27
26
  response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "backend", :backend_id => backend_id})
28
- commit_routes unless options[:skip_commit]
27
+ commit_routes if options[:commit]
29
28
  response
30
29
  end
31
30
 
32
31
  def add_redirect_route(path, type, destination, redirect_type = "permanent", options = {})
33
32
  response = put_json!("#{endpoint}/routes", :route => {:incoming_path => path, :route_type => type, :handler => "redirect",
34
33
  :redirect_to => destination, :redirect_type => redirect_type})
35
- commit_routes unless options[:skip_commit]
34
+ commit_routes if options[:commit]
36
35
  response
37
36
  end
38
37
 
39
38
  def delete_route(path, type, options = {})
40
39
  response = delete_json!("#{endpoint}/routes?incoming_path=#{CGI.escape(path)}&route_type=#{CGI.escape(type)}")
41
- commit_routes unless options[:skip_commit]
40
+ commit_routes if options[:commit]
42
41
  response
43
42
  end
44
43
 
@@ -5,6 +5,19 @@ module GdsApi
5
5
  module Router
6
6
  ROUTER_API_ENDPOINT = Plek.current.find('router-api')
7
7
 
8
+ def stub_all_router_registration
9
+ stub_request(:put, %r{\A#{ROUTER_API_ENDPOINT}/backends/[a-z0-9-]+\z})
10
+ stub_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
11
+ stub_request(:post, "#{ROUTER_API_ENDPOINT}/routes/commit")
12
+ end
13
+
14
+ def stub_router_backend_registration(backend_id, backend_url)
15
+ backend = { "backend" => { "backend_url" => backend_url }}
16
+ stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/backends/#{backend_id}")
17
+ .with(:body => backend.to_json)
18
+ .to_return(:status => 201)
19
+ end
20
+
8
21
  def stub_route_registration(path, type, backend_id)
9
22
  route = { route: {
10
23
  incoming_path: path,
@@ -13,8 +26,9 @@ module GdsApi
13
26
  backend_id: backend_id }
14
27
  }
15
28
 
16
- stub_router_put(route)
17
- stub_http_request(:post, "#{ROUTER_API_ENDPOINT}/routes/commit")
29
+ register_stub = stub_route_put(route)
30
+ commit_stub = stub_router_commit
31
+ [register_stub, commit_stub]
18
32
  end
19
33
 
20
34
  def stub_redirect_registration(path, type, destination, redirect_type)
@@ -26,13 +40,18 @@ module GdsApi
26
40
  redirect_type: redirect_type }
27
41
  }
28
42
 
29
- stub_router_put(redirect)
43
+ register_stub = stub_route_put(redirect)
44
+ commit_stub = stub_router_commit
45
+ [register_stub, commit_stub]
46
+ end
47
+
48
+ def stub_router_commit
30
49
  stub_http_request(:post, "#{ROUTER_API_ENDPOINT}/routes/commit")
31
50
  end
32
51
 
33
52
  private
34
53
 
35
- def stub_router_put(route)
54
+ def stub_route_put(route)
36
55
  stub_http_request(:put, "#{ROUTER_API_ENDPOINT}/routes")
37
56
  .with(:body => route.to_json)
38
57
  .to_return(:status => 201)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '10.17.1'
2
+ VERSION = '11.0.0'
3
3
  end
data/test/router_test.rb CHANGED
@@ -199,17 +199,17 @@ describe GdsApi::Router do
199
199
  assert_equal "foo", response.backend_id
200
200
 
201
201
  assert_requested(req)
202
- assert_requested(@commit_req)
202
+ assert_not_requested(@commit_req)
203
203
  end
204
204
 
205
- it "should not commit the routes when asked not to" do
205
+ it "should commit the routes when asked to" do
206
206
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
207
207
  to_return(:status => 201, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
208
208
 
209
- @api.add_route("/foo", "exact", "foo", :skip_commit => true)
209
+ @api.add_route("/foo", "exact", "foo", :commit => true)
210
210
 
211
211
  assert_requested(req)
212
- assert_not_requested(@commit_req)
212
+ assert_requested(@commit_req)
213
213
  end
214
214
 
215
215
  it "should raise an error if creating/updating the route fails" do
@@ -248,7 +248,7 @@ describe GdsApi::Router do
248
248
  assert_equal "/bar", response.redirect_to
249
249
 
250
250
  assert_requested(req)
251
- assert_requested(@commit_req)
251
+ assert_not_requested(@commit_req)
252
252
  end
253
253
 
254
254
  it "should allow creating/updating a temporary redirect route" do
@@ -262,17 +262,17 @@ describe GdsApi::Router do
262
262
  assert_equal "/bar", response.redirect_to
263
263
 
264
264
  assert_requested(req)
265
- assert_requested(@commit_req)
265
+ assert_not_requested(@commit_req)
266
266
  end
267
267
 
268
- it "should not commit the routes when asked not to" do
268
+ it "should commit the routes when asked to" do
269
269
  req = WebMock.stub_request(:put, "#{@base_api_url}/routes").
270
270
  to_return(:status => 201, :body =>{}.to_json, :headers => {"Content-type" => "application/json"})
271
271
 
272
- @api.add_redirect_route("/foo", "exact", "/bar", "temporary", :skip_commit => true)
272
+ @api.add_redirect_route("/foo", "exact", "/bar", "temporary", :commit => true)
273
273
 
274
274
  assert_requested(req)
275
- assert_not_requested(@commit_req)
275
+ assert_requested(@commit_req)
276
276
  end
277
277
 
278
278
  it "should raise an error if creating/updating the redirect route fails" do
@@ -311,18 +311,18 @@ describe GdsApi::Router do
311
311
  assert_equal "foo", response.backend_id
312
312
 
313
313
  assert_requested(req)
314
- assert_requested(@commit_req)
314
+ assert_not_requested(@commit_req)
315
315
  end
316
316
 
317
- it "should not commit the routes when asked not to" do
317
+ it "should commit the routes when asked to" do
318
318
  req = WebMock.stub_request(:delete, "#{@base_api_url}/routes").
319
319
  with(:query => {"incoming_path" => "/foo", "route_type" => "exact"}).
320
320
  to_return(:status => 200, :body => {}.to_json, :headers => {"Content-type" => "application/json"})
321
321
 
322
- @api.delete_route("/foo", "exact", :skip_commit => true)
322
+ @api.delete_route("/foo", "exact", :commit => true)
323
323
 
324
324
  assert_requested(req)
325
- assert_not_requested(@commit_req)
325
+ assert_requested(@commit_req)
326
326
  end
327
327
 
328
328
  it "should raise HTTPNotFound if nothing found" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.17.1
4
+ version: 11.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -382,7 +382,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
382
382
  version: '0'
383
383
  segments:
384
384
  - 0
385
- hash: -186651956250723834
385
+ hash: -1694392773198955183
386
386
  required_rubygems_version: !ruby/object:Gem::Requirement
387
387
  none: false
388
388
  requirements:
@@ -391,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
391
  version: '0'
392
392
  segments:
393
393
  - 0
394
- hash: -186651956250723834
394
+ hash: -1694392773198955183
395
395
  requirements: []
396
396
  rubyforge_project:
397
397
  rubygems_version: 1.8.23