prefab-cloud-ruby 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/README.md +9 -0
- data/VERSION +1 -1
- data/lib/prefab/client.rb +29 -37
- data/lib/prefab/config_client.rb +107 -85
- data/lib/prefab/config_helper.rb +8 -0
- data/lib/prefab/config_loader.rb +30 -9
- data/lib/prefab/config_resolver.rb +22 -18
- data/lib/prefab/feature_flag_client.rb +23 -26
- data/lib/prefab/internal_logger.rb +28 -0
- data/lib/prefab/logger_client.rb +1 -1
- data/lib/prefab/options.rb +81 -0
- data/lib/prefab/prefab.rb +32 -0
- data/lib/prefab-cloud-ruby.rb +2 -0
- data/lib/prefab_pb.rb +21 -17
- data/lib/prefab_services_pb.rb +14 -0
- data/prefab-cloud-ruby.gemspec +7 -3
- data/test/.prefab.test.config.yaml +5 -1
- data/test/harness_server.rb +2 -1
- data/test/test_config_client.rb +19 -0
- data/test/test_config_loader.rb +32 -18
- data/test/test_config_resolver.rb +34 -28
- data/test/test_feature_flag_client.rb +37 -44
- data/test/test_helper.rb +4 -4
- metadata +6 -2
@@ -75,32 +75,6 @@ class TestFeatureFlagClient < Minitest::Test
|
|
75
75
|
@client.evaluate(feature, "hashes low", [], flag, variants)
|
76
76
|
end
|
77
77
|
|
78
|
-
def test_user_targets
|
79
|
-
|
80
|
-
feature = "FlagName"
|
81
|
-
variants = [
|
82
|
-
Prefab::FeatureFlagVariant.new(string: "inactive"),
|
83
|
-
Prefab::FeatureFlagVariant.new(string: "user target"),
|
84
|
-
Prefab::FeatureFlagVariant.new(string: "default"),
|
85
|
-
]
|
86
|
-
flag = Prefab::FeatureFlag.new(
|
87
|
-
active: true,
|
88
|
-
inactive_variant_idx: 1,
|
89
|
-
user_targets: [
|
90
|
-
variant_idx: 2,
|
91
|
-
identifiers: ["user:1", "user:3"]
|
92
|
-
],
|
93
|
-
rules: default_ff_rule(3)
|
94
|
-
)
|
95
|
-
|
96
|
-
assert_equal "user target",
|
97
|
-
@client.evaluate(feature, "user:1", [], flag, variants)
|
98
|
-
assert_equal "default",
|
99
|
-
@client.evaluate(feature, "user:2", [], flag, variants)
|
100
|
-
assert_equal "user target",
|
101
|
-
@client.evaluate(feature, "user:3", [], flag, variants)
|
102
|
-
end
|
103
|
-
|
104
78
|
def test_inclusion_rule
|
105
79
|
feature = "FlagName"
|
106
80
|
variants = [
|
@@ -174,34 +148,46 @@ class TestFeatureFlagClient < Minitest::Test
|
|
174
148
|
)
|
175
149
|
|
176
150
|
assert_equal "default",
|
177
|
-
@client.evaluate(feature, "user:1", {email: "not@example.com"}, flag, variants)
|
151
|
+
@client.evaluate(feature, "user:1", { email: "not@example.com" }, flag, variants)
|
178
152
|
assert_equal "default",
|
179
153
|
@client.evaluate(feature, "user:2", {}, flag, variants)
|
180
154
|
assert_equal "rule target",
|
181
|
-
@client.evaluate(feature, "user:2", {email: "b@example.com"}, flag, variants)
|
155
|
+
@client.evaluate(feature, "user:2", { email: "b@example.com" }, flag, variants)
|
182
156
|
assert_equal "rule target",
|
183
|
-
@client.evaluate(feature, "user:2", {"email" => "b@example.com"}, flag, variants)
|
157
|
+
@client.evaluate(feature, "user:2", { "email" => "b@example.com" }, flag, variants)
|
184
158
|
|
185
159
|
end
|
186
160
|
|
187
161
|
def test_segment_match?
|
188
162
|
segment = Prefab::Segment.new(
|
189
|
-
|
190
|
-
|
191
|
-
|
163
|
+
criterion: [
|
164
|
+
Prefab::Criteria.new(
|
165
|
+
operator: "PROP_IS_ONE_OF",
|
166
|
+
values: ["a@example.com", "b@example.com"],
|
167
|
+
property: "email"
|
168
|
+
),
|
169
|
+
Prefab::Criteria.new(
|
170
|
+
operator: "LOOKUP_KEY_IN",
|
171
|
+
values: ["user:2"]
|
172
|
+
)
|
173
|
+
]
|
192
174
|
)
|
193
175
|
assert_equal false, @client.segment_match?(segment, "user:0", {})
|
194
|
-
assert_equal
|
195
|
-
assert_equal false, @client.segment_match?(segment, "user:
|
196
|
-
assert_equal true, @client.segment_match?(segment, "user:
|
176
|
+
assert_equal true, @client.segment_match?(segment, "user:2", {})
|
177
|
+
assert_equal false, @client.segment_match?(segment, "user:1", { email: "no@example.com" })
|
178
|
+
assert_equal true, @client.segment_match?(segment, "user:1", { email: "a@example.com" })
|
197
179
|
end
|
198
180
|
|
199
181
|
def test_segments
|
200
182
|
segment_key = "prefab-segment-beta-group"
|
201
183
|
@mock_base_client.config_client.mock_this_config(segment_key,
|
202
184
|
Prefab::Segment.new(
|
203
|
-
|
204
|
-
|
185
|
+
criterion: [
|
186
|
+
Prefab::Criteria.new(
|
187
|
+
operator: Prefab::Criteria::CriteriaOperator::LOOKUP_KEY_IN,
|
188
|
+
values: ["user:1"]
|
189
|
+
)
|
190
|
+
]
|
205
191
|
)
|
206
192
|
)
|
207
193
|
|
@@ -247,17 +233,23 @@ class TestFeatureFlagClient < Minitest::Test
|
|
247
233
|
segment_key_one = "prefab-segment-segment-1"
|
248
234
|
@mock_base_client.config_client.mock_this_config(segment_key_one,
|
249
235
|
Prefab::Segment.new(
|
250
|
-
|
251
|
-
|
252
|
-
|
236
|
+
criterion: [
|
237
|
+
Prefab::Criteria.new(
|
238
|
+
operator: Prefab::Criteria::CriteriaOperator::LOOKUP_KEY_IN,
|
239
|
+
values: ["user:1", "user:2"]
|
240
|
+
)
|
241
|
+
]
|
253
242
|
)
|
254
243
|
)
|
255
244
|
segment_key_two = "prefab-segment-segment-2"
|
256
245
|
@mock_base_client.config_client.mock_this_config(segment_key_two,
|
257
246
|
Prefab::Segment.new(
|
258
|
-
|
259
|
-
|
260
|
-
|
247
|
+
criterion: [
|
248
|
+
Prefab::Criteria.new(
|
249
|
+
operator: Prefab::Criteria::CriteriaOperator::LOOKUP_KEY_IN,
|
250
|
+
values: ["user:3", "user:4"]
|
251
|
+
)
|
252
|
+
]
|
261
253
|
)
|
262
254
|
)
|
263
255
|
|
@@ -288,7 +280,8 @@ class TestFeatureFlagClient < Minitest::Test
|
|
288
280
|
variant_idx: 3)
|
289
281
|
]
|
290
282
|
)
|
291
|
-
|
283
|
+
|
284
|
+
],
|
292
285
|
)
|
293
286
|
|
294
287
|
assert_equal "rule target",
|
data/test/test_helper.rb
CHANGED
@@ -5,12 +5,12 @@ class MockBaseClient
|
|
5
5
|
STAGING_ENV_ID = 1
|
6
6
|
PRODUCTION_ENV_ID = 2
|
7
7
|
TEST_ENV_ID = 3
|
8
|
-
attr_reader :namespace, :logger, :config_client
|
9
|
-
|
10
|
-
def initialize(namespace: "")
|
8
|
+
attr_reader :namespace, :logger, :config_client, :options
|
11
9
|
|
10
|
+
def initialize(options = Prefab::Options.new)
|
11
|
+
@options = options
|
12
12
|
@namespace = namespace
|
13
|
-
@logger =
|
13
|
+
@logger = Prefab::LoggerClient.new($stdout)
|
14
14
|
@config_client = MockConfigClient.new
|
15
15
|
end
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prefab-cloud-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dwyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -225,10 +225,13 @@ files:
|
|
225
225
|
- lib/prefab/config_loader.rb
|
226
226
|
- lib/prefab/config_resolver.rb
|
227
227
|
- lib/prefab/feature_flag_client.rb
|
228
|
+
- lib/prefab/internal_logger.rb
|
228
229
|
- lib/prefab/logger_client.rb
|
229
230
|
- lib/prefab/murmer3.rb
|
230
231
|
- lib/prefab/noop_cache.rb
|
231
232
|
- lib/prefab/noop_stats.rb
|
233
|
+
- lib/prefab/options.rb
|
234
|
+
- lib/prefab/prefab.rb
|
232
235
|
- lib/prefab/ratelimit_client.rb
|
233
236
|
- lib/prefab_pb.rb
|
234
237
|
- lib/prefab_services_pb.rb
|
@@ -236,6 +239,7 @@ files:
|
|
236
239
|
- run_test_harness_server.sh
|
237
240
|
- test/.prefab.test.config.yaml
|
238
241
|
- test/harness_server.rb
|
242
|
+
- test/test_config_client.rb
|
239
243
|
- test/test_config_loader.rb
|
240
244
|
- test/test_config_resolver.rb
|
241
245
|
- test/test_feature_flag_client.rb
|