sitehub 0.5.0.alpha4 → 0.5.0.alpha5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sitehub/identifier.rb +7 -1
- data/lib/sitehub/route_builder.rb +5 -4
- data/lib/sitehub/version.rb +1 -1
- data/spec/sitehub/identifier_spec.rb +12 -0
- data/spec/sitehub/integration_spec.rb +11 -12
- data/spec/sitehub/middleware/routes_spec.rb +1 -1
- data/spec/sitehub/route_builder_spec.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7189b64635170892f88906d52c53a757bdffd12
|
4
|
+
data.tar.gz: c928e7fb8bcb65d9375b6ac448298de8f6d6449f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c57e15219c0a8f28e450b294b143db8b6d9b7851cbca600618c174533020116eda0dbbfb989c7179f827b8c4e3f95fe7b47bc129b3a4a7be05f339b34148640
|
7
|
+
data.tar.gz: d87d4cab4c1d81cea2cd40d269a579e916d89e023d598e44fe2210500981a317237508b3bbca11ed467b28d8da337c80afa0ed4a84dec655ccb5aacdfb33c20a
|
data/Gemfile.lock
CHANGED
data/lib/sitehub/identifier.rb
CHANGED
@@ -11,7 +11,7 @@ class SiteHub
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def root
|
14
|
-
components.first
|
14
|
+
Identifier.new(components.first)
|
15
15
|
end
|
16
16
|
|
17
17
|
def sub_id
|
@@ -33,5 +33,11 @@ class SiteHub
|
|
33
33
|
def ==(other)
|
34
34
|
other.respond_to?(:to_sym) && to_sym == other.to_sym
|
35
35
|
end
|
36
|
+
|
37
|
+
def hash
|
38
|
+
components.hash
|
39
|
+
end
|
40
|
+
|
41
|
+
alias eql? ==
|
36
42
|
end
|
37
43
|
end
|
@@ -67,17 +67,18 @@ class SiteHub
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def add_route(label:, rule: nil, percentage: nil, url: nil, &block)
|
70
|
-
|
70
|
+
child_label = id.child_label(label)
|
71
|
+
|
71
72
|
route = if block
|
72
73
|
raise InvalidDefinitionException, RULE_NOT_SPECIFIED_MSG unless percentage || rule
|
73
74
|
warn(IGNORING_URL_MSG) if url
|
74
|
-
new(rule: rule, id:
|
75
|
+
new(rule: rule, id: child_label, &block).build
|
75
76
|
else
|
76
77
|
raise InvalidDefinitionException, RULE_NOT_SPECIFIED_MSG unless url
|
77
|
-
forward_proxy(url: url, label:
|
78
|
+
forward_proxy(url: url, label: child_label, rule: rule)
|
78
79
|
end
|
79
80
|
|
80
|
-
routes.add(label, route, percentage)
|
81
|
+
routes.add(Identifier.new(label), route, percentage)
|
81
82
|
end
|
82
83
|
|
83
84
|
def default_route
|
data/lib/sitehub/version.rb
CHANGED
@@ -8,6 +8,18 @@ class SiteHub
|
|
8
8
|
described_class.new(nil)
|
9
9
|
end
|
10
10
|
|
11
|
+
describe '#hash' do
|
12
|
+
it 'returns the hash off the components' do
|
13
|
+
expect(subject.hash).to be(subject.components.hash)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#eql?' do
|
18
|
+
it 'is an alias of the #== method' do
|
19
|
+
expect(subject.method(:eql?)).to eq(subject.method(:==))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe '#initialize' do
|
12
24
|
context 'id supplied' do
|
13
25
|
it 'it returns a concatenated id' do
|
@@ -7,8 +7,8 @@ shared_context :site_hub do
|
|
7
7
|
|
8
8
|
before do
|
9
9
|
WebMock.enable!
|
10
|
-
stub_request(:get, experiment1_url).to_return(body: '
|
11
|
-
stub_request(:get, experiment2_url).to_return(body: '
|
10
|
+
stub_request(:get, experiment1_url).to_return(body: 'experiment1_body')
|
11
|
+
stub_request(:get, experiment2_url).to_return(body: 'experiment2_body')
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:builder) do
|
@@ -24,7 +24,8 @@ shared_context :site_hub do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
split(label: :experiment2, percentage: 0) do
|
27
|
-
split percentage:
|
27
|
+
split percentage: 0, label: 'variant1', url: experiment2_url
|
28
|
+
split percentage: 100, label: 'variant2', url: experiment2_url
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
@@ -52,7 +53,6 @@ describe 'proxying calls' do
|
|
52
53
|
describe 'route affinity' do
|
53
54
|
context 'requested route cookie not present' do
|
54
55
|
it 'drops a cookie to keep you on the same path' do
|
55
|
-
stub_request(:get, downstream_url).to_return(body: 'hello')
|
56
56
|
get('/endpoint')
|
57
57
|
expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment1|variant1')
|
58
58
|
end
|
@@ -61,7 +61,7 @@ describe 'proxying calls' do
|
|
61
61
|
context 'requested route cookie present' do
|
62
62
|
it 'proxies to the preselected route' do
|
63
63
|
get('/endpoint', {}, 'HTTP_COOKIE' => "#{SiteHub::RECORDED_ROUTES_COOKIE}=experiment2|variant1")
|
64
|
-
expect(app.last_response.body).to eq(['
|
64
|
+
expect(app.last_response.body).to eq(['experiment2_body'])
|
65
65
|
|
66
66
|
expect(app.last_response.cookies[SiteHub::RECORDED_ROUTES_COOKIE][:value]).to eq('experiment2|variant1')
|
67
67
|
end
|
@@ -78,13 +78,12 @@ describe 'proxying calls' do
|
|
78
78
|
# create_middleware.tap do |clazz|
|
79
79
|
# clazz.class_eval do
|
80
80
|
# define_method :call do |env|
|
81
|
+
#
|
81
82
|
# callback = env['async.callback'] || env['async.orig_callback']
|
82
83
|
# env['async.orig_callback'] = env['async.callback'] = proc do |status, headers, body|
|
83
|
-
# if body.is_a?(Rack::BodyProxy)
|
84
|
-
# body = "#{name}, #{body.body.join}"
|
85
|
-
# end
|
84
|
+
# body = body.body.join if body.is_a?(Rack::BodyProxy)
|
86
85
|
#
|
87
|
-
# callback.call(status, headers, body)
|
86
|
+
# callback.call(status, headers, "#{name}, #{body}")
|
88
87
|
# end
|
89
88
|
# @app.call(env)
|
90
89
|
# end
|
@@ -153,13 +152,13 @@ describe 'proxying calls' do
|
|
153
152
|
# use middleware2
|
154
153
|
# route label: :with_middleware, url: downstream_url
|
155
154
|
# end
|
156
|
-
#
|
155
|
+
# proxy '/2' => downstream_url
|
157
156
|
# end
|
158
157
|
# end
|
159
158
|
#
|
160
159
|
# it 'adds it to that route only' do
|
161
160
|
# get('/1')
|
162
|
-
# expect(app.last_response.body.join).to eq('middleware1, middleware2,
|
161
|
+
# expect(app.last_response.body.join).to eq('middleware1, middleware2, hello')
|
163
162
|
# get('/2')
|
164
163
|
# expect(app.last_response.body.join).to eq('middleware1, hello')
|
165
164
|
# end
|
@@ -177,7 +176,7 @@ describe 'proxying calls' do
|
|
177
176
|
# proxy '/1' do
|
178
177
|
# split percentage: 100, label: :experiment1 do
|
179
178
|
# use middleware1
|
180
|
-
# split percentage: 100, label: :with_middleware
|
179
|
+
# split percentage: 100, label: :with_middleware do
|
181
180
|
# use middleware2
|
182
181
|
# split percentage: 100, label: :with_nested_middleware, url: downstream_url
|
183
182
|
# end
|
@@ -69,7 +69,7 @@ class SiteHub
|
|
69
69
|
context 'mapped_route found' do
|
70
70
|
it 'uses the forward proxy' do
|
71
71
|
subject
|
72
|
-
expect(forward_proxy_builder.routes[:current]).to receive(:call) do
|
72
|
+
expect(forward_proxy_builder.routes[Identifier.new(:current)]).to receive(:call) do
|
73
73
|
[200, {}, []]
|
74
74
|
end
|
75
75
|
expect(get(mapped_path).status).to eq(200)
|
@@ -9,7 +9,7 @@ class SiteHub
|
|
9
9
|
include_context :sitehub_json
|
10
10
|
|
11
11
|
subject do
|
12
|
-
described_class.from_hash(proxy_1, :expected).routes[route_1[:label]]
|
12
|
+
described_class.from_hash(proxy_1, :expected).routes[Identifier.new(route_1[:label])]
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'splits' do
|
@@ -164,7 +164,7 @@ class SiteHub
|
|
164
164
|
sitehub_cookie_name: :cookie_name,
|
165
165
|
sitehub_cookie_path: nil)
|
166
166
|
|
167
|
-
expect(subject.routes[:current]).to eq(expected_route)
|
167
|
+
expect(subject.routes[Identifier.new(:current)]).to eq(expected_route)
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'accepts a rule' do
|
@@ -198,7 +198,7 @@ class SiteHub
|
|
198
198
|
mapped_path: '/path',
|
199
199
|
&block).build
|
200
200
|
|
201
|
-
expect(subject.routes[:label1]).to eq(expected_endpoints)
|
201
|
+
expect(subject.routes[Identifier.new(:label1)]).to eq(expected_endpoints)
|
202
202
|
subject.build
|
203
203
|
end
|
204
204
|
|
@@ -250,9 +250,9 @@ class SiteHub
|
|
250
250
|
context 'middleware not specified' do
|
251
251
|
it 'leaves it the proxies alone' do
|
252
252
|
subject.route url: :url, label: :current
|
253
|
-
expect(subject.routes[:current]).to be_using_rack_stack(ForwardProxy)
|
253
|
+
expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(ForwardProxy)
|
254
254
|
subject.build
|
255
|
-
expect(subject.routes[:current]).to be_using_rack_stack(ForwardProxy)
|
255
|
+
expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(ForwardProxy)
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
@@ -264,7 +264,7 @@ class SiteHub
|
|
264
264
|
it 'wraps the forward proxies in the middleware' do
|
265
265
|
subject.route url: :url, label: :current
|
266
266
|
subject.build
|
267
|
-
expect(subject.routes[:current]).to be_using_rack_stack(middleware, ForwardProxy)
|
267
|
+
expect(subject.routes[Identifier.new(:current)]).to be_using_rack_stack(middleware, ForwardProxy)
|
268
268
|
end
|
269
269
|
|
270
270
|
it 'wraps the default in the middleware' do
|