sitehub 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -0
  3. data/Gemfile +0 -2
  4. data/Gemfile.lock +15 -1
  5. data/README.md +23 -0
  6. data/Rakefile +3 -9
  7. data/circle.yml +6 -0
  8. data/lib/sitehub/builder.rb +19 -19
  9. data/lib/sitehub/collection/route_collection.rb +7 -9
  10. data/lib/sitehub/collection/split_route_collection/split.rb +7 -5
  11. data/lib/sitehub/collection/split_route_collection.rb +13 -10
  12. data/lib/sitehub/collection.rb +26 -21
  13. data/lib/sitehub/constants/http_header_keys.rb +2 -6
  14. data/lib/sitehub/constants/rack_http_header_keys.rb +2 -2
  15. data/lib/sitehub/constants.rb +3 -3
  16. data/lib/sitehub/cookie/attribute.rb +4 -4
  17. data/lib/sitehub/cookie/flag.rb +4 -5
  18. data/lib/sitehub/cookie.rb +10 -14
  19. data/lib/sitehub/cookie_rewriting.rb +11 -13
  20. data/lib/sitehub/forward_proxies.rb +12 -13
  21. data/lib/sitehub/forward_proxy.rb +38 -24
  22. data/lib/sitehub/forward_proxy_builder.rb +38 -21
  23. data/lib/sitehub/http_headers.rb +39 -26
  24. data/lib/sitehub/logging/access_logger.rb +39 -35
  25. data/lib/sitehub/logging/error_logger.rb +7 -7
  26. data/lib/sitehub/logging/log_entry.rb +6 -5
  27. data/lib/sitehub/logging/log_stash.rb +2 -2
  28. data/lib/sitehub/logging/log_wrapper.rb +5 -5
  29. data/lib/sitehub/logging.rb +1 -1
  30. data/lib/sitehub/middleware.rb +2 -2
  31. data/lib/sitehub/path_directive.rb +10 -10
  32. data/lib/sitehub/path_directives.rb +5 -4
  33. data/lib/sitehub/request_mapping.rb +13 -11
  34. data/lib/sitehub/resolver.rb +5 -6
  35. data/lib/sitehub/reverse_proxy.rb +16 -12
  36. data/lib/sitehub/rules.rb +2 -2
  37. data/lib/sitehub/string_sanitiser.rb +1 -1
  38. data/lib/sitehub/transaction_id.rb +3 -3
  39. data/lib/sitehub/version.rb +1 -1
  40. data/lib/sitehub.rb +1 -1
  41. data/sitehub.gemspec +27 -29
  42. data/spec/sitehub/builder_spec.rb +18 -20
  43. data/spec/sitehub/collection/route_collection_spec.rb +16 -14
  44. data/spec/sitehub/collection/split_route_collection_spec.rb +8 -10
  45. data/spec/sitehub/collection_spec.rb +7 -7
  46. data/spec/sitehub/cookie/attribute_spec.rb +3 -3
  47. data/spec/sitehub/cookie/flag_spec.rb +2 -2
  48. data/spec/sitehub/cookie_rewriting_spec.rb +15 -12
  49. data/spec/sitehub/cookie_spec.rb +7 -18
  50. data/spec/sitehub/error_handling_spec.rb +2 -3
  51. data/spec/sitehub/forward_proxies_spec.rb +16 -12
  52. data/spec/sitehub/forward_proxy_builder_spec.rb +53 -30
  53. data/spec/sitehub/forward_proxy_spec.rb +26 -22
  54. data/spec/sitehub/http_headers_spec.rb +17 -18
  55. data/spec/sitehub/integration_spec.rb +4 -5
  56. data/spec/sitehub/logging/access_logger_spec.rb +25 -24
  57. data/spec/sitehub/logging/error_logger_spec.rb +5 -7
  58. data/spec/sitehub/logging/log_entry_spec.rb +2 -5
  59. data/spec/sitehub/logging/log_stash_spec.rb +1 -3
  60. data/spec/sitehub/logging/log_wrapper_spec.rb +0 -4
  61. data/spec/sitehub/middleware_spec.rb +1 -5
  62. data/spec/sitehub/path_directive_spec.rb +4 -7
  63. data/spec/sitehub/path_directives_spec.rb +6 -7
  64. data/spec/sitehub/request_mapping_spec.rb +2 -5
  65. data/spec/sitehub/resolver_spec.rb +1 -1
  66. data/spec/sitehub/reverse_proxy_spec.rb +37 -31
  67. data/spec/sitehub/transaction_id_spec.rb +3 -3
  68. data/spec/sitehub_spec.rb +2 -4
  69. data/spec/support/async/callback.rb +11 -0
  70. data/spec/support/async/middleware.rb +25 -0
  71. data/spec/support/async/response_handler.rb +16 -0
  72. data/spec/support/async.rb +4 -0
  73. data/spec/support/patch/rack/response.rb +13 -21
  74. data/spec/support/shared_contexts/async_context.rb +3 -58
  75. data/spec/support/shared_contexts/middleware_context.rb +15 -17
  76. data/spec/support/shared_contexts/rack_test_context.rb +3 -3
  77. data/spec/support/shared_contexts/sitehub_context.rb +9 -4
  78. data/spec/support/silent_warnings.rb +2 -3
  79. data/tasks/code_quality.rake +15 -0
  80. data/tasks/gem_tasks.rake +1 -0
  81. data/tasks/support/console.rb +7 -0
  82. data/tasks/testing.rake +4 -0
  83. data/tasks/util_tasks.rake +7 -0
  84. metadata +27 -3
  85. data/spec/basket_spec.rb +0 -30
@@ -1,17 +1,22 @@
1
1
  require 'stringio'
2
2
  shared_context :site_hub do
3
-
4
- let(:downstream_url){'http://localhost:12345'}
3
+ let(:downstream_url) { 'http://localhost:12345' }
5
4
 
6
5
  before do
7
- stub_request(:get, downstream_url).to_return(:body => 'hello')
6
+ stub_request(:get, downstream_url).to_return(body: 'hello')
8
7
  end
9
8
 
10
9
  let(:builder) do
11
10
  SiteHub::Builder.new.tap do |builder|
12
11
  builder.access_logger StringIO.new
13
12
  builder.error_logger StringIO.new
14
- builder.proxy "/endpoint" => downstream_url
13
+ downstream_url = downstream_url()
14
+ builder.proxy '/endpoint' do
15
+ split(percentage: 100) do
16
+ split percentage: 50, label: 'experiment1', url: downstream_url
17
+ split percentage: 50, label: 'experiment2', url: downstream_url
18
+ end
19
+ end
15
20
  end
16
21
  end
17
22
 
@@ -1,5 +1,4 @@
1
1
  class Object
2
- def warn message
3
-
2
+ def warn(message)
4
3
  end
5
- end
4
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ require 'rubocop/rake_task'
3
+ $LOAD_PATH.unshift(__dir__)
4
+ require 'support/console'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task :coverage_check do
9
+ required_percentage = 100
10
+ percentage = JSON(File.read("#{__dir__}/../coverage/.last_run.json"))['result']['covered_percent']
11
+ unless percentage == required_percentage
12
+ Console.error "Expected coverage: #{required_percentage}% got: #{percentage}%"
13
+ exit 1
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,7 @@
1
+ module Console
2
+ class << self
3
+ def error(message)
4
+ puts "[ \033[0;31mERROR\033[0m ] #{message}"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+ RSpec::Core::RakeTask.new(:spec) do
3
+ ENV['coverage'] = 'true'
4
+ end
@@ -0,0 +1,7 @@
1
+ task :clean do
2
+ directories = %w(coverage)
3
+ directories.each do |dir|
4
+ dir = "#{__dir__}/../#{dir}"
5
+ FileUtils.rm_rf(dir) if File.exist?(dir)
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitehub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ladtech
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - ">="
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rubocop
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: memory_profiler
225
239
  requirement: !ruby/object:Gem::Requirement
@@ -257,11 +271,13 @@ extra_rdoc_files: []
257
271
  files:
258
272
  - ".gitignore"
259
273
  - ".rspec"
274
+ - ".rubocop.yml"
260
275
  - Gemfile
261
276
  - Gemfile.lock
262
277
  - LICENSE
263
278
  - README.md
264
279
  - Rakefile
280
+ - circle.yml
265
281
  - lib/sitehub.rb
266
282
  - lib/sitehub/builder.rb
267
283
  - lib/sitehub/collection.rb
@@ -297,7 +313,6 @@ files:
297
313
  - lib/sitehub/version.rb
298
314
  - mem_usage.txt
299
315
  - sitehub.gemspec
300
- - spec/basket_spec.rb
301
316
  - spec/sitehub/builder_spec.rb
302
317
  - spec/sitehub/collection/route_collection_spec.rb
303
318
  - spec/sitehub/collection/split_route_collection_spec.rb
@@ -326,12 +341,21 @@ files:
326
341
  - spec/sitehub/transaction_id_spec.rb
327
342
  - spec/sitehub_spec.rb
328
343
  - spec/spec_helper.rb
344
+ - spec/support/async.rb
345
+ - spec/support/async/callback.rb
346
+ - spec/support/async/middleware.rb
347
+ - spec/support/async/response_handler.rb
329
348
  - spec/support/patch/rack/response.rb
330
349
  - spec/support/shared_contexts/async_context.rb
331
350
  - spec/support/shared_contexts/middleware_context.rb
332
351
  - spec/support/shared_contexts/rack_test_context.rb
333
352
  - spec/support/shared_contexts/sitehub_context.rb
334
353
  - spec/support/silent_warnings.rb
354
+ - tasks/code_quality.rake
355
+ - tasks/gem_tasks.rake
356
+ - tasks/support/console.rb
357
+ - tasks/testing.rake
358
+ - tasks/util_tasks.rake
335
359
  homepage: ''
336
360
  licenses:
337
361
  - MIT
data/spec/basket_spec.rb DELETED
@@ -1,30 +0,0 @@
1
- class Basket
2
-
3
- attr_reader :items
4
- def initialize shopping_list
5
- @items = parse(shopping_list)
6
- end
7
-
8
- def parse shopping_list
9
- shopping_list.lines[1..-1].collect { |item|
10
- item.chomp.to_sym
11
- }
12
- end
13
- end
14
-
15
- describe Basket do
16
-
17
- describe '#initialize' do
18
- it 'takes a shopping list' do
19
-
20
- shopping_list=<<LIST
21
- list
22
- apple
23
- carrot
24
- LIST
25
-
26
- basket = described_class.new(shopping_list)
27
- expect(basket.items).to eq([:apple, :carrot])
28
- end
29
- end
30
- end