launchdarkly-server-sdk 5.8.0 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +28 -122
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.gitignore +2 -1
- data/.ldrelease/build-docs.sh +18 -0
- data/.ldrelease/circleci/linux/execute.sh +18 -0
- data/.ldrelease/circleci/mac/execute.sh +18 -0
- data/.ldrelease/circleci/template/build.sh +29 -0
- data/.ldrelease/circleci/template/publish.sh +23 -0
- data/.ldrelease/circleci/template/set-gem-home.sh +7 -0
- data/.ldrelease/circleci/template/test.sh +10 -0
- data/.ldrelease/circleci/template/update-version.sh +8 -0
- data/.ldrelease/circleci/windows/execute.ps1 +19 -0
- data/.ldrelease/config.yml +14 -2
- data/CHANGELOG.md +29 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +4 -3
- data/azure-pipelines.yml +1 -1
- data/docs/Makefile +26 -0
- data/docs/index.md +9 -0
- data/launchdarkly-server-sdk.gemspec +20 -13
- data/lib/ldclient-rb.rb +0 -1
- data/lib/ldclient-rb/config.rb +15 -3
- data/lib/ldclient-rb/evaluation_detail.rb +293 -0
- data/lib/ldclient-rb/events.rb +6 -7
- data/lib/ldclient-rb/file_data_source.rb +1 -1
- data/lib/ldclient-rb/impl/evaluator.rb +225 -0
- data/lib/ldclient-rb/impl/evaluator_bucketing.rb +74 -0
- data/lib/ldclient-rb/impl/evaluator_operators.rb +160 -0
- data/lib/ldclient-rb/impl/event_factory.rb +22 -0
- data/lib/ldclient-rb/impl/event_sender.rb +56 -40
- data/lib/ldclient-rb/impl/integrations/consul_impl.rb +5 -5
- data/lib/ldclient-rb/impl/integrations/dynamodb_impl.rb +5 -5
- data/lib/ldclient-rb/impl/integrations/redis_impl.rb +5 -7
- data/lib/ldclient-rb/impl/model/serialization.rb +62 -0
- data/lib/ldclient-rb/impl/unbounded_pool.rb +34 -0
- data/lib/ldclient-rb/ldclient.rb +38 -17
- data/lib/ldclient-rb/polling.rb +1 -4
- data/lib/ldclient-rb/requestor.rb +25 -23
- data/lib/ldclient-rb/stream.rb +10 -30
- data/lib/ldclient-rb/util.rb +12 -8
- data/lib/ldclient-rb/version.rb +1 -1
- data/spec/evaluation_detail_spec.rb +135 -0
- data/spec/event_sender_spec.rb +20 -2
- data/spec/events_spec.rb +10 -0
- data/spec/http_util.rb +11 -1
- data/spec/impl/evaluator_bucketing_spec.rb +111 -0
- data/spec/impl/evaluator_clause_spec.rb +55 -0
- data/spec/impl/evaluator_operators_spec.rb +141 -0
- data/spec/impl/evaluator_rule_spec.rb +96 -0
- data/spec/impl/evaluator_segment_spec.rb +125 -0
- data/spec/impl/evaluator_spec.rb +305 -0
- data/spec/impl/evaluator_spec_base.rb +75 -0
- data/spec/impl/model/serialization_spec.rb +41 -0
- data/spec/launchdarkly-server-sdk_spec.rb +1 -1
- data/spec/ldclient_end_to_end_spec.rb +34 -0
- data/spec/ldclient_spec.rb +64 -12
- data/spec/polling_spec.rb +2 -2
- data/spec/redis_feature_store_spec.rb +2 -2
- data/spec/requestor_spec.rb +11 -45
- data/spec/spec_helper.rb +0 -3
- data/spec/stream_spec.rb +1 -16
- metadata +111 -61
- data/.yardopts +0 -9
- data/Gemfile.lock +0 -100
- data/lib/ldclient-rb/evaluation.rb +0 -462
- data/scripts/gendocs.sh +0 -11
- data/scripts/release.sh +0 -27
- data/spec/evaluation_spec.rb +0 -789
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module LaunchDarkly
|
4
|
+
module Impl
|
5
|
+
module EvaluatorSpecBase
|
6
|
+
def factory
|
7
|
+
EventFactory.new(false)
|
8
|
+
end
|
9
|
+
|
10
|
+
def user
|
11
|
+
{
|
12
|
+
key: "userkey",
|
13
|
+
email: "test@example.com",
|
14
|
+
name: "Bob"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
::Logger.new($stdout, level: ::Logger::FATAL)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_nothing
|
23
|
+
lambda { |key| raise "should not have requested #{key}" }
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_things(map)
|
27
|
+
lambda { |key|
|
28
|
+
raise "should not have requested #{key}" if !map.has_key?(key)
|
29
|
+
map[key]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def basic_evaluator
|
34
|
+
subject.new(get_nothing, get_nothing, logger)
|
35
|
+
end
|
36
|
+
|
37
|
+
def boolean_flag_with_rules(rules)
|
38
|
+
{ key: 'feature', on: true, rules: rules, fallthrough: { variation: 0 }, variations: [ false, true ] }
|
39
|
+
end
|
40
|
+
|
41
|
+
def boolean_flag_with_clauses(clauses)
|
42
|
+
boolean_flag_with_rules([{ id: 'ruleid', clauses: clauses, variation: 1 }])
|
43
|
+
end
|
44
|
+
|
45
|
+
def make_user_matching_clause(user, attr)
|
46
|
+
{
|
47
|
+
attribute: attr.to_s,
|
48
|
+
op: :in,
|
49
|
+
values: [ user[attr.to_sym] ],
|
50
|
+
negate: false
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def make_segment(key)
|
55
|
+
{
|
56
|
+
key: key,
|
57
|
+
included: [],
|
58
|
+
excluded: [],
|
59
|
+
salt: 'abcdef',
|
60
|
+
version: 1
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def make_segment_match_clause(segment)
|
65
|
+
{
|
66
|
+
op: :segmentMatch,
|
67
|
+
values: [ segment[:key] ],
|
68
|
+
negate: false
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
RSpec.configure { |c| c.include EvaluatorSpecBase, :evaluator_spec_base => true }
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module LaunchDarkly
|
4
|
+
module Impl
|
5
|
+
module Model
|
6
|
+
describe "model serialization" do
|
7
|
+
it "serializes flag" do
|
8
|
+
flag = { key: "flagkey", version: 1 }
|
9
|
+
json = Model.serialize(FEATURES, flag)
|
10
|
+
expect(JSON.parse(json, symbolize_names: true)).to eq flag
|
11
|
+
end
|
12
|
+
|
13
|
+
it "serializes segment" do
|
14
|
+
segment = { key: "segkey", version: 1 }
|
15
|
+
json = Model.serialize(SEGMENTS, segment)
|
16
|
+
expect(JSON.parse(json, symbolize_names: true)).to eq segment
|
17
|
+
end
|
18
|
+
|
19
|
+
it "serializes arbitrary data kind" do
|
20
|
+
thing = { key: "thingkey", name: "me" }
|
21
|
+
json = Model.serialize({ name: "things" }, thing)
|
22
|
+
expect(JSON.parse(json, symbolize_names: true)).to eq thing
|
23
|
+
end
|
24
|
+
|
25
|
+
it "deserializes flag with no rules or prerequisites" do
|
26
|
+
flag_in = { key: "flagkey", version: 1 }
|
27
|
+
json = Model.serialize(FEATURES, flag_in)
|
28
|
+
flag_out = Model.deserialize(FEATURES, json)
|
29
|
+
expect(flag_out).to eq flag_in
|
30
|
+
end
|
31
|
+
|
32
|
+
it "deserializes segment" do
|
33
|
+
segment_in = { key: "segkey", version: 1 }
|
34
|
+
json = Model.serialize(SEGMENTS, segment_in)
|
35
|
+
segment_out = Model.deserialize(SEGMENTS, json)
|
36
|
+
expect(segment_out).to eq segment_in
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,7 +4,7 @@ require "bundler"
|
|
4
4
|
describe LaunchDarkly do
|
5
5
|
it "can be automatically loaded by Bundler.require" do
|
6
6
|
ldclient_loaded =
|
7
|
-
Bundler.
|
7
|
+
Bundler.with_unbundled_env do
|
8
8
|
Kernel.system("ruby", "./spec/launchdarkly-server-sdk_spec_autoloadtest.rb")
|
9
9
|
end
|
10
10
|
|
@@ -80,6 +80,7 @@ module LaunchDarkly
|
|
80
80
|
|
81
81
|
req, body = events_server.await_request_with_body
|
82
82
|
expect(req.header['authorization']).to eq [ SDK_KEY ]
|
83
|
+
expect(req.header['connection']).to eq [ "Keep-Alive" ]
|
83
84
|
data = JSON.parse(body)
|
84
85
|
expect(data.length).to eq 1
|
85
86
|
expect(data[0]["kind"]).to eq "identify"
|
@@ -111,6 +112,7 @@ module LaunchDarkly
|
|
111
112
|
req = req0.path == "/diagnostic" ? req0 : req1
|
112
113
|
body = req0.path == "/diagnostic" ? body0 : body1
|
113
114
|
expect(req.header['authorization']).to eq [ SDK_KEY ]
|
115
|
+
expect(req.header['connection']).to eq [ "Keep-Alive" ]
|
114
116
|
data = JSON.parse(body)
|
115
117
|
expect(data["kind"]).to eq "diagnostic-init"
|
116
118
|
end
|
@@ -118,6 +120,38 @@ module LaunchDarkly
|
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
123
|
+
it "can use socket factory" do
|
124
|
+
with_server do |poll_server|
|
125
|
+
with_server do |events_server|
|
126
|
+
events_server.setup_ok_response("/bulk", "")
|
127
|
+
poll_server.setup_ok_response("/sdk/latest-all", '{"flags":{},"segments":{}}', "application/json")
|
128
|
+
|
129
|
+
config = Config.new(
|
130
|
+
stream: false,
|
131
|
+
base_uri: "http://polling.com",
|
132
|
+
events_uri: "http://events.com",
|
133
|
+
diagnostic_opt_out: true,
|
134
|
+
logger: NullLogger.new,
|
135
|
+
socket_factory: SocketFactoryFromHash.new({
|
136
|
+
"polling.com" => poll_server.port,
|
137
|
+
"events.com" => events_server.port
|
138
|
+
})
|
139
|
+
)
|
140
|
+
with_client(config) do |client|
|
141
|
+
client.identify(USER)
|
142
|
+
client.flush
|
143
|
+
|
144
|
+
req, body = events_server.await_request_with_body
|
145
|
+
expect(req.header['authorization']).to eq [ SDK_KEY ]
|
146
|
+
expect(req.header['connection']).to eq [ "Keep-Alive" ]
|
147
|
+
data = JSON.parse(body)
|
148
|
+
expect(data.length).to eq 1
|
149
|
+
expect(data[0]["kind"]).to eq "identify"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
121
155
|
# TODO: TLS tests with self-signed cert
|
122
156
|
end
|
123
157
|
end
|
data/spec/ldclient_spec.rb
CHANGED
@@ -25,6 +25,12 @@ describe LaunchDarkly::LDClient do
|
|
25
25
|
}
|
26
26
|
}
|
27
27
|
end
|
28
|
+
let(:user_anonymous) do
|
29
|
+
{
|
30
|
+
key: "anonymous@test.com",
|
31
|
+
anonymous: true
|
32
|
+
}
|
33
|
+
end
|
28
34
|
let(:numeric_key_user) do
|
29
35
|
{
|
30
36
|
key: 33,
|
@@ -139,20 +145,30 @@ describe LaunchDarkly::LDClient do
|
|
139
145
|
client.variation("key", user, "default")
|
140
146
|
end
|
141
147
|
|
142
|
-
it "
|
148
|
+
it "does not send an event if user is nil" do
|
149
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
150
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
151
|
+
expect(event_processor).not_to receive(:add_event)
|
152
|
+
expect(logger).to receive(:error)
|
153
|
+
client.variation("key", nil, "default")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "queues a feature event for an existing feature when user is anonymous" do
|
143
157
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
144
158
|
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
145
159
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
146
160
|
kind: "feature",
|
147
161
|
key: "key",
|
148
162
|
version: 100,
|
149
|
-
|
150
|
-
|
163
|
+
contextKind: "anonymousUser",
|
164
|
+
user: user_anonymous,
|
165
|
+
variation: 0,
|
166
|
+
value: "value",
|
151
167
|
default: "default",
|
152
168
|
trackEvents: true,
|
153
169
|
debugEventsUntilDate: 1000
|
154
170
|
))
|
155
|
-
client.variation("key",
|
171
|
+
client.variation("key", user_anonymous, "default")
|
156
172
|
end
|
157
173
|
|
158
174
|
it "queues a feature event for an existing feature when user key is nil" do
|
@@ -197,7 +213,7 @@ describe LaunchDarkly::LDClient do
|
|
197
213
|
value: 'value',
|
198
214
|
default: 'default',
|
199
215
|
trackEvents: true,
|
200
|
-
reason:
|
216
|
+
reason: LaunchDarkly::EvaluationReason::rule_match(0, 'id')
|
201
217
|
))
|
202
218
|
client.variation('flag', user, 'default')
|
203
219
|
end
|
@@ -222,7 +238,7 @@ describe LaunchDarkly::LDClient do
|
|
222
238
|
value: 'value',
|
223
239
|
default: 'default',
|
224
240
|
trackEvents: true,
|
225
|
-
reason:
|
241
|
+
reason: LaunchDarkly::EvaluationReason::fallthrough
|
226
242
|
))
|
227
243
|
client.variation('flag', user, 'default')
|
228
244
|
end
|
@@ -234,20 +250,22 @@ describe LaunchDarkly::LDClient do
|
|
234
250
|
|
235
251
|
it "returns the default value if the client is offline" do
|
236
252
|
result = offline_client.variation_detail("doesntmatter", user, "default")
|
237
|
-
expected = LaunchDarkly::EvaluationDetail.new("default", nil,
|
253
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil,
|
254
|
+
LaunchDarkly::EvaluationReason::error(LaunchDarkly::EvaluationReason::ERROR_CLIENT_NOT_READY))
|
238
255
|
expect(result).to eq expected
|
239
256
|
end
|
240
257
|
|
241
258
|
it "returns the default value for an unknown feature" do
|
242
259
|
result = client.variation_detail("badkey", user, "default")
|
243
|
-
expected = LaunchDarkly::EvaluationDetail.new("default", nil,
|
260
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil,
|
261
|
+
LaunchDarkly::EvaluationReason::error(LaunchDarkly::EvaluationReason::ERROR_FLAG_NOT_FOUND))
|
244
262
|
expect(result).to eq expected
|
245
263
|
end
|
246
264
|
|
247
265
|
it "queues a feature request event for an unknown feature" do
|
248
266
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
249
267
|
kind: "feature", key: "badkey", user: user, value: "default", default: "default",
|
250
|
-
reason:
|
268
|
+
reason: LaunchDarkly::EvaluationReason::error(LaunchDarkly::EvaluationReason::ERROR_FLAG_NOT_FOUND)
|
251
269
|
))
|
252
270
|
client.variation_detail("badkey", user, "default")
|
253
271
|
end
|
@@ -256,7 +274,7 @@ describe LaunchDarkly::LDClient do
|
|
256
274
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
257
275
|
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
258
276
|
result = client.variation_detail("key", user, "default")
|
259
|
-
expected = LaunchDarkly::EvaluationDetail.new("value", 0,
|
277
|
+
expected = LaunchDarkly::EvaluationDetail.new("value", 0, LaunchDarkly::EvaluationReason::off)
|
260
278
|
expect(result).to eq expected
|
261
279
|
end
|
262
280
|
|
@@ -265,7 +283,7 @@ describe LaunchDarkly::LDClient do
|
|
265
283
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
266
284
|
config.feature_store.upsert(LaunchDarkly::FEATURES, empty_feature)
|
267
285
|
result = client.variation_detail("key", user, "default")
|
268
|
-
expected = LaunchDarkly::EvaluationDetail.new("default", nil,
|
286
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil, LaunchDarkly::EvaluationReason::off)
|
269
287
|
expect(result).to eq expected
|
270
288
|
expect(result.default_value?).to be true
|
271
289
|
end
|
@@ -283,10 +301,18 @@ describe LaunchDarkly::LDClient do
|
|
283
301
|
default: "default",
|
284
302
|
trackEvents: true,
|
285
303
|
debugEventsUntilDate: 1000,
|
286
|
-
reason:
|
304
|
+
reason: LaunchDarkly::EvaluationReason::off
|
287
305
|
))
|
288
306
|
client.variation_detail("key", user, "default")
|
289
307
|
end
|
308
|
+
|
309
|
+
it "does not send an event if user is nil" do
|
310
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
311
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
312
|
+
expect(event_processor).not_to receive(:add_event)
|
313
|
+
expect(logger).to receive(:error)
|
314
|
+
client.variation_detail("key", nil, "default")
|
315
|
+
end
|
290
316
|
end
|
291
317
|
|
292
318
|
describe '#all_flags' do
|
@@ -453,6 +479,12 @@ describe LaunchDarkly::LDClient do
|
|
453
479
|
client.track("custom_event_name", user, nil, 1.5)
|
454
480
|
end
|
455
481
|
|
482
|
+
it "includes contextKind with anonymous user" do
|
483
|
+
expect(event_processor).to receive(:add_event).with(hash_including(
|
484
|
+
kind: "custom", key: "custom_event_name", user: user_anonymous, metricValue: 2.2, contextKind: "anonymousUser"))
|
485
|
+
client.track("custom_event_name", user_anonymous, nil, 2.2)
|
486
|
+
end
|
487
|
+
|
456
488
|
it "sanitizes the user in the event" do
|
457
489
|
expect(event_processor).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
|
458
490
|
client.track("custom_event_name", numeric_key_user, nil)
|
@@ -471,6 +503,26 @@ describe LaunchDarkly::LDClient do
|
|
471
503
|
end
|
472
504
|
end
|
473
505
|
|
506
|
+
describe '#alias' do
|
507
|
+
it "queues up an alias event" do
|
508
|
+
expect(event_processor).to receive(:add_event).with(hash_including(
|
509
|
+
kind: "alias", key: user[:key], contextKind: "user", previousKey: user_anonymous[:key], previousContextKind: "anonymousUser"))
|
510
|
+
client.alias(user, user_anonymous)
|
511
|
+
end
|
512
|
+
|
513
|
+
it "does not send an event, and logs a warning, if user is nil" do
|
514
|
+
expect(event_processor).not_to receive(:add_event)
|
515
|
+
expect(logger).to receive(:warn)
|
516
|
+
client.alias(nil, nil)
|
517
|
+
end
|
518
|
+
|
519
|
+
it "does not send an event, and logs a warning, if user key is nil" do
|
520
|
+
expect(event_processor).not_to receive(:add_event)
|
521
|
+
expect(logger).to receive(:warn)
|
522
|
+
client.alias(user_without_key, user_without_key)
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
474
526
|
describe '#identify' do
|
475
527
|
it "queues up an identify event" do
|
476
528
|
expect(event_processor).to receive(:add_event).with(hash_including(kind: "identify", key: user[:key], user: user))
|
data/spec/polling_spec.rb
CHANGED
@@ -19,10 +19,10 @@ describe LaunchDarkly::PollingProcessor do
|
|
19
19
|
flag = { key: 'flagkey', version: 1 }
|
20
20
|
segment = { key: 'segkey', version: 1 }
|
21
21
|
all_data = {
|
22
|
-
|
22
|
+
LaunchDarkly::FEATURES => {
|
23
23
|
flagkey: flag
|
24
24
|
},
|
25
|
-
|
25
|
+
LaunchDarkly::SEGMENTS => {
|
26
26
|
segkey: segment
|
27
27
|
}
|
28
28
|
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require "connection_pool"
|
2
1
|
require "feature_store_spec_base"
|
2
|
+
require "connection_pool"
|
3
3
|
require "json"
|
4
4
|
require "redis"
|
5
5
|
require "spec_helper"
|
@@ -28,7 +28,7 @@ end
|
|
28
28
|
|
29
29
|
describe LaunchDarkly::RedisFeatureStore do
|
30
30
|
subject { LaunchDarkly::RedisFeatureStore }
|
31
|
-
|
31
|
+
|
32
32
|
break if ENV['LD_SKIP_DATABASE_TESTS'] == '1'
|
33
33
|
|
34
34
|
# These tests will all fail if there isn't a Redis instance running on the default port.
|
data/spec/requestor_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe LaunchDarkly::Requestor do
|
|
35
35
|
with_requestor(server.base_uri.to_s) do |requestor|
|
36
36
|
server.setup_ok_response("/", expected_data.to_json)
|
37
37
|
data = requestor.request_all_data()
|
38
|
-
expect(data).to eq expected_data
|
38
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -91,7 +91,7 @@ describe LaunchDarkly::Requestor do
|
|
91
91
|
data = requestor.request_all_data()
|
92
92
|
expect(server.requests.count).to eq 2
|
93
93
|
expect(server.requests[1].header).to include({ "if-none-match" => [ etag ] })
|
94
|
-
expect(data).to eq expected_data
|
94
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -109,14 +109,14 @@ describe LaunchDarkly::Requestor do
|
|
109
109
|
res["ETag"] = etag1
|
110
110
|
end
|
111
111
|
data = requestor.request_all_data()
|
112
|
-
expect(data).to eq expected_data1
|
112
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data1)
|
113
113
|
expect(server.requests.count).to eq 1
|
114
114
|
|
115
115
|
server.setup_response("/") do |req, res|
|
116
116
|
res.status = 304
|
117
117
|
end
|
118
118
|
data = requestor.request_all_data()
|
119
|
-
expect(data).to eq expected_data1
|
119
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data1)
|
120
120
|
expect(server.requests.count).to eq 2
|
121
121
|
expect(server.requests[1].header).to include({ "if-none-match" => [ etag1 ] })
|
122
122
|
|
@@ -126,7 +126,7 @@ describe LaunchDarkly::Requestor do
|
|
126
126
|
res["ETag"] = etag2
|
127
127
|
end
|
128
128
|
data = requestor.request_all_data()
|
129
|
-
expect(data).to eq expected_data2
|
129
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data2)
|
130
130
|
expect(server.requests.count).to eq 3
|
131
131
|
expect(server.requests[2].header).to include({ "if-none-match" => [ etag1 ] })
|
132
132
|
|
@@ -134,7 +134,7 @@ describe LaunchDarkly::Requestor do
|
|
134
134
|
res.status = 304
|
135
135
|
end
|
136
136
|
data = requestor.request_all_data()
|
137
|
-
expect(data).to eq expected_data2
|
137
|
+
expect(data).to eq LaunchDarkly::Impl::Model.make_all_store_data(expected_data2)
|
138
138
|
expect(server.requests.count).to eq 4
|
139
139
|
expect(server.requests[3].header).to include({ "if-none-match" => [ etag2 ] })
|
140
140
|
end
|
@@ -147,7 +147,7 @@ describe LaunchDarkly::Requestor do
|
|
147
147
|
server.setup_ok_response("/sdk/latest-all", content, "application/json")
|
148
148
|
with_requestor(server.base_uri.to_s) do |requestor|
|
149
149
|
data = requestor.request_all_data
|
150
|
-
expect(data).to eq(JSON.parse(content, symbolize_names: true))
|
150
|
+
expect(data).to eq(LaunchDarkly::Impl::Model.make_all_store_data(JSON.parse(content, symbolize_names: true)))
|
151
151
|
end
|
152
152
|
end
|
153
153
|
end
|
@@ -159,7 +159,7 @@ describe LaunchDarkly::Requestor do
|
|
159
159
|
"text/plain; charset=ISO-8859-2")
|
160
160
|
with_requestor(server.base_uri.to_s) do |requestor|
|
161
161
|
data = requestor.request_all_data
|
162
|
-
expect(data).to eq(JSON.parse(content, symbolize_names: true))
|
162
|
+
expect(data).to eq(LaunchDarkly::Impl::Model.make_all_store_data(JSON.parse(content, symbolize_names: true)))
|
163
163
|
end
|
164
164
|
end
|
165
165
|
end
|
@@ -176,15 +176,15 @@ describe LaunchDarkly::Requestor do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "can use a proxy server" do
|
179
|
-
|
179
|
+
expected_data = { flags: { flagkey: { key: "flagkey" } } }
|
180
180
|
with_server do |server|
|
181
|
-
server.setup_ok_response("/sdk/latest-all",
|
181
|
+
server.setup_ok_response("/sdk/latest-all", expected_data.to_json, "application/json", { "etag" => "x" })
|
182
182
|
with_server(StubProxyServer.new) do |proxy|
|
183
183
|
begin
|
184
184
|
ENV["http_proxy"] = proxy.base_uri.to_s
|
185
185
|
with_requestor(server.base_uri.to_s) do |requestor|
|
186
186
|
data = requestor.request_all_data
|
187
|
-
expect(data).to eq(
|
187
|
+
expect(data).to eq(LaunchDarkly::Impl::Model.make_all_store_data(expected_data))
|
188
188
|
end
|
189
189
|
ensure
|
190
190
|
ENV["http_proxy"] = nil
|
@@ -193,38 +193,4 @@ describe LaunchDarkly::Requestor do
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
end
|
196
|
-
|
197
|
-
describe "request_flag" do
|
198
|
-
it "uses expected URI and headers" do
|
199
|
-
with_server do |server|
|
200
|
-
with_requestor(server.base_uri.to_s) do |requestor|
|
201
|
-
server.setup_ok_response("/", "{}")
|
202
|
-
requestor.request_flag("key")
|
203
|
-
expect(server.requests.count).to eq 1
|
204
|
-
expect(server.requests[0].unparsed_uri).to eq "/sdk/latest-flags/key"
|
205
|
-
expect(server.requests[0].header).to include({
|
206
|
-
"authorization" => [ $sdk_key ],
|
207
|
-
"user-agent" => [ "RubyClient/" + LaunchDarkly::VERSION ]
|
208
|
-
})
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "request_segment" do
|
215
|
-
it "uses expected URI and headers" do
|
216
|
-
with_server do |server|
|
217
|
-
with_requestor(server.base_uri.to_s) do |requestor|
|
218
|
-
server.setup_ok_response("/", "{}")
|
219
|
-
requestor.request_segment("key")
|
220
|
-
expect(server.requests.count).to eq 1
|
221
|
-
expect(server.requests[0].unparsed_uri).to eq "/sdk/latest-segments/key"
|
222
|
-
expect(server.requests[0].header).to include({
|
223
|
-
"authorization" => [ $sdk_key ],
|
224
|
-
"user-agent" => [ "RubyClient/" + LaunchDarkly::VERSION ]
|
225
|
-
})
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
196
|
end
|