prefab-cloud-ruby 0.8.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +24 -0
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/prefab/client.rb +12 -8
- data/lib/prefab/config_client.rb +51 -19
- data/lib/prefab/config_loader.rb +12 -10
- data/lib/prefab/config_resolver.rb +36 -38
- data/lib/prefab/feature_flag_client.rb +40 -27
- data/lib/prefab-cloud-ruby.rb +2 -0
- data/lib/prefab_pb.rb +47 -44
- data/lib/prefab_services_pb.rb +17 -3
- data/prefab-cloud-ruby.gemspec +5 -3
- data/run_test_harness_server.sh +1 -1
- data/test/harness_server.rb +12 -4
- data/test/test_config_loader.rb +20 -20
- data/test/test_config_resolver.rb +72 -52
- data/test/test_feature_flag_client.rb +195 -108
- data/test/test_helper.rb +42 -6
- data/test/test_logger.rb +0 -10
- metadata +16 -2
data/lib/prefab_pb.rb
CHANGED
@@ -8,7 +8,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
8
8
|
add_message "prefab.ConfigServicePointer" do
|
9
9
|
optional :project_id, :int64, 1
|
10
10
|
optional :start_at_id, :int64, 2
|
11
|
-
optional :
|
11
|
+
optional :project_env_id, :int64, 3
|
12
12
|
end
|
13
13
|
add_message "prefab.ConfigValue" do
|
14
14
|
oneof :type do
|
@@ -22,28 +22,22 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
22
22
|
optional :segment, :message, 8, "prefab.Segment"
|
23
23
|
end
|
24
24
|
end
|
25
|
-
add_message "prefab.
|
26
|
-
|
27
|
-
optional :
|
25
|
+
add_message "prefab.Configs" do
|
26
|
+
repeated :configs, :message, 1, "prefab.Config"
|
27
|
+
optional :config_service_pointer, :message, 2, "prefab.ConfigServicePointer"
|
28
28
|
end
|
29
|
-
add_message "prefab.
|
30
|
-
optional :environment, :string, 1
|
31
|
-
repeated :namespace_values, :message, 2, "prefab.NamespaceValue"
|
32
|
-
optional :default, :message, 3, "prefab.ConfigValue"
|
33
|
-
end
|
34
|
-
add_message "prefab.ConfigDelta" do
|
29
|
+
add_message "prefab.Config" do
|
35
30
|
optional :id, :int64, 1
|
36
|
-
optional :
|
37
|
-
optional :
|
38
|
-
repeated :envs, :message, 4, "prefab.EnvironmentValues"
|
39
|
-
end
|
40
|
-
add_message "prefab.ConfigDeltas" do
|
41
|
-
repeated :deltas, :message, 1, "prefab.ConfigDelta"
|
42
|
-
end
|
43
|
-
add_message "prefab.UpsertRequest" do
|
44
|
-
optional :project_id, :int64, 1
|
45
|
-
optional :config_delta, :message, 2, "prefab.ConfigDelta"
|
31
|
+
optional :project_id, :int64, 2
|
32
|
+
optional :key, :string, 3
|
46
33
|
optional :changed_by, :string, 4
|
34
|
+
repeated :rows, :message, 5, "prefab.ConfigRow"
|
35
|
+
repeated :variants, :message, 6, "prefab.FeatureFlagVariant"
|
36
|
+
end
|
37
|
+
add_message "prefab.ConfigRow" do
|
38
|
+
optional :project_env_id, :int64, 1
|
39
|
+
optional :namespace, :string, 2
|
40
|
+
optional :value, :message, 3, "prefab.ConfigValue"
|
47
41
|
end
|
48
42
|
add_message "prefab.LimitResponse" do
|
49
43
|
optional :passed, :bool, 1
|
@@ -97,15 +91,19 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
97
91
|
end
|
98
92
|
add_enum "prefab.Criteria.CriteriaOperator" do
|
99
93
|
value :NOT_SET, 0
|
100
|
-
value :
|
101
|
-
value :
|
102
|
-
value :
|
103
|
-
value :
|
104
|
-
value :
|
94
|
+
value :LOOKUP_KEY_IN, 1
|
95
|
+
value :LOOKUP_KEY_NOT_IN, 2
|
96
|
+
value :IN_SEG, 3
|
97
|
+
value :NOT_IN_SEG, 4
|
98
|
+
value :ALWAYS_TRUE, 5
|
99
|
+
value :PROP_IS_ONE_OF, 6
|
100
|
+
value :PROP_IS_NOT_ONE_OF, 7
|
101
|
+
value :PROP_ENDS_WITH_ONE_OF, 8
|
102
|
+
value :PROP_DOES_NOT_END_WITH_ONE_OF, 9
|
105
103
|
end
|
106
104
|
add_message "prefab.Rule" do
|
107
105
|
optional :criteria, :message, 1, "prefab.Criteria"
|
108
|
-
|
106
|
+
repeated :variant_weights, :message, 2, "prefab.VariantWeight"
|
109
107
|
end
|
110
108
|
add_message "prefab.Segment" do
|
111
109
|
optional :name, :string, 1
|
@@ -122,22 +120,11 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
122
120
|
optional :weight, :int32, 1
|
123
121
|
optional :variant_idx, :int32, 2
|
124
122
|
end
|
125
|
-
add_message "prefab.VariantWeights" do
|
126
|
-
repeated :weights, :message, 1, "prefab.VariantWeight"
|
127
|
-
end
|
128
|
-
add_message "prefab.VariantDistribution" do
|
129
|
-
oneof :type do
|
130
|
-
optional :variant_idx, :int32, 1
|
131
|
-
optional :variant_weights, :message, 2, "prefab.VariantWeights"
|
132
|
-
end
|
133
|
-
end
|
134
123
|
add_message "prefab.FeatureFlag" do
|
135
124
|
optional :active, :bool, 1
|
136
125
|
optional :inactive_variant_idx, :int32, 2
|
137
|
-
optional :default, :message, 3, "prefab.VariantDistribution"
|
138
126
|
repeated :user_targets, :message, 4, "prefab.UserTarget"
|
139
127
|
repeated :rules, :message, 5, "prefab.Rule"
|
140
|
-
repeated :variants, :message, 6, "prefab.FeatureFlagVariant"
|
141
128
|
end
|
142
129
|
add_message "prefab.LimitDefinition" do
|
143
130
|
optional :policy_name, :enum, 2, "prefab.LimitResponse.LimitPolicyNames"
|
@@ -177,6 +164,23 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
177
164
|
add_message "prefab.BasicResponse" do
|
178
165
|
optional :message, :string, 1
|
179
166
|
end
|
167
|
+
add_message "prefab.CreationResponse" do
|
168
|
+
optional :message, :string, 1
|
169
|
+
optional :new_id, :int64, 2
|
170
|
+
end
|
171
|
+
add_message "prefab.IdBlock" do
|
172
|
+
optional :project_id, :int64, 1
|
173
|
+
optional :project_env_id, :int64, 2
|
174
|
+
optional :sequence_name, :string, 3
|
175
|
+
optional :start, :int64, 4
|
176
|
+
optional :end, :int64, 5
|
177
|
+
end
|
178
|
+
add_message "prefab.IdBlockRequest" do
|
179
|
+
optional :project_id, :int64, 1
|
180
|
+
optional :project_env_id, :int64, 2
|
181
|
+
optional :sequence_name, :string, 3
|
182
|
+
optional :size, :int64, 4
|
183
|
+
end
|
180
184
|
add_enum "prefab.OnFailure" do
|
181
185
|
value :NOT_SET, 0
|
182
186
|
value :LOG_AND_PASS, 1
|
@@ -189,11 +193,9 @@ end
|
|
189
193
|
module Prefab
|
190
194
|
ConfigServicePointer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigServicePointer").msgclass
|
191
195
|
ConfigValue = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigValue").msgclass
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
ConfigDeltas = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigDeltas").msgclass
|
196
|
-
UpsertRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.UpsertRequest").msgclass
|
196
|
+
Configs = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.Configs").msgclass
|
197
|
+
Config = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.Config").msgclass
|
198
|
+
ConfigRow = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.ConfigRow").msgclass
|
197
199
|
LimitResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitResponse").msgclass
|
198
200
|
LimitResponse::LimitPolicyNames = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitResponse.LimitPolicyNames").enummodule
|
199
201
|
LimitRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitRequest").msgclass
|
@@ -205,8 +207,6 @@ module Prefab
|
|
205
207
|
Segment = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.Segment").msgclass
|
206
208
|
UserTarget = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.UserTarget").msgclass
|
207
209
|
VariantWeight = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.VariantWeight").msgclass
|
208
|
-
VariantWeights = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.VariantWeights").msgclass
|
209
|
-
VariantDistribution = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.VariantDistribution").msgclass
|
210
210
|
FeatureFlag = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.FeatureFlag").msgclass
|
211
211
|
LimitDefinition = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitDefinition").msgclass
|
212
212
|
LimitDefinition::SafetyLevel = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.LimitDefinition.SafetyLevel").enummodule
|
@@ -214,5 +214,8 @@ module Prefab
|
|
214
214
|
BufferedRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BufferedRequest").msgclass
|
215
215
|
BatchRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BatchRequest").msgclass
|
216
216
|
BasicResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.BasicResponse").msgclass
|
217
|
+
CreationResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.CreationResponse").msgclass
|
218
|
+
IdBlock = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlock").msgclass
|
219
|
+
IdBlockRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.IdBlockRequest").msgclass
|
217
220
|
OnFailure = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("prefab.OnFailure").enummodule
|
218
221
|
end
|
data/lib/prefab_services_pb.rb
CHANGED
@@ -28,9 +28,23 @@ module Prefab
|
|
28
28
|
self.unmarshal_class_method = :decode
|
29
29
|
self.service_name = 'prefab.ConfigService'
|
30
30
|
|
31
|
-
rpc :GetConfig, ::Prefab::ConfigServicePointer, stream(::Prefab::
|
32
|
-
rpc :GetAllConfig, ::Prefab::ConfigServicePointer, ::Prefab::
|
33
|
-
rpc :Upsert, ::Prefab::
|
31
|
+
rpc :GetConfig, ::Prefab::ConfigServicePointer, stream(::Prefab::Configs)
|
32
|
+
rpc :GetAllConfig, ::Prefab::ConfigServicePointer, ::Prefab::Configs
|
33
|
+
rpc :Upsert, ::Prefab::Config, ::Prefab::CreationResponse
|
34
|
+
end
|
35
|
+
|
36
|
+
Stub = Service.rpc_stub_class
|
37
|
+
end
|
38
|
+
module IdService
|
39
|
+
class Service
|
40
|
+
|
41
|
+
include ::GRPC::GenericService
|
42
|
+
|
43
|
+
self.marshal_class_method = :encode
|
44
|
+
self.unmarshal_class_method = :decode
|
45
|
+
self.service_name = 'prefab.IdService'
|
46
|
+
|
47
|
+
rpc :GetBlock, ::Prefab::IdBlockRequest, ::Prefab::IdBlock
|
34
48
|
end
|
35
49
|
|
36
50
|
Stub = Service.rpc_stub_class
|
data/prefab-cloud-ruby.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: prefab-cloud-ruby 0.
|
5
|
+
# stub: prefab-cloud-ruby 0.11.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "prefab-cloud-ruby".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.11.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Jeff Dwyer".freeze]
|
14
|
-
s.date = "2022-
|
14
|
+
s.date = "2022-05-05"
|
15
15
|
s.description = "RateLimits & Config as a service".freeze
|
16
16
|
s.email = "jdwyer@prefab.cloud".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
|
|
67
67
|
if s.respond_to? :add_runtime_dependency then
|
68
68
|
s.add_runtime_dependency(%q<concurrent-ruby>.freeze, ["~> 1.0", ">= 1.0.5"])
|
69
69
|
s.add_runtime_dependency(%q<faraday>.freeze, [">= 0"])
|
70
|
+
s.add_runtime_dependency(%q<ld-eventsource>.freeze, [">= 0"])
|
70
71
|
s.add_runtime_dependency(%q<grpc>.freeze, [">= 0"])
|
71
72
|
s.add_runtime_dependency(%q<google-protobuf>.freeze, [">= 0"])
|
72
73
|
s.add_runtime_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
|
@@ -80,6 +81,7 @@ Gem::Specification.new do |s|
|
|
80
81
|
else
|
81
82
|
s.add_dependency(%q<concurrent-ruby>.freeze, ["~> 1.0", ">= 1.0.5"])
|
82
83
|
s.add_dependency(%q<faraday>.freeze, [">= 0"])
|
84
|
+
s.add_dependency(%q<ld-eventsource>.freeze, [">= 0"])
|
83
85
|
s.add_dependency(%q<grpc>.freeze, [">= 0"])
|
84
86
|
s.add_dependency(%q<google-protobuf>.freeze, [">= 0"])
|
85
87
|
s.add_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
|
data/run_test_harness_server.sh
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL=debug PREFAB_CLOUD_HTTP=true
|
1
|
+
PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL=debug PREFAB_CLOUD_HTTP=true PREFAB_GRPC_URL="localhost:50051" ruby -Ilib test/harness_server.rb
|
2
2
|
#GRPC_TRACE=all GRPC_VERBOSITY=DEBUG PREFAB_LOG_CLIENT_BOOTSTRAP_LOG_LEVEL=debug PREFAB_CLOUD_HTTP=true PREFAB_API_KEY="1|local_development_api_key" PREFAB_API_URL="localhost:50051" ruby -Ilib test/harness_server.rb
|
data/test/harness_server.rb
CHANGED
@@ -15,31 +15,39 @@ class RackApp
|
|
15
15
|
|
16
16
|
key = props["key"]
|
17
17
|
namespace = props["namespace"]
|
18
|
-
|
18
|
+
api_key = props["api_key"]
|
19
19
|
user_key = props["user_key"]
|
20
20
|
is_feature_flag = !props["feature_flag"].nil?
|
21
|
-
|
21
|
+
puts props
|
22
22
|
client = Prefab::Client.new(
|
23
|
-
api_key:
|
23
|
+
api_key: api_key,
|
24
24
|
namespace: namespace,
|
25
25
|
)
|
26
26
|
|
27
27
|
puts "Key #{key}"
|
28
28
|
puts "User #{user_key}"
|
29
|
-
puts "
|
29
|
+
puts "api_key #{api_key}"
|
30
30
|
puts "Namespace #{namespace}"
|
31
31
|
puts "Props! #{props}"
|
32
32
|
puts "is_feature_flag! #{is_feature_flag}"
|
33
33
|
|
34
|
+
puts client.config_client.to_s
|
35
|
+
|
34
36
|
if is_feature_flag
|
35
37
|
puts "EVALFF #{key} #{user_key}"
|
36
38
|
rtn = client.feature_flag_client.get(key, user_key, []).to_s
|
37
39
|
else
|
38
40
|
rtn = client.config_client.get(key).to_s
|
39
41
|
end
|
42
|
+
|
40
43
|
puts "return #{rtn}"
|
41
44
|
|
42
45
|
[200, { "Content-Type" => "text/plain" }, rtn]
|
46
|
+
|
47
|
+
rescue Exception => e
|
48
|
+
puts "ERROR #{e.message}"
|
49
|
+
puts e.backtrace
|
50
|
+
[500, { "Content-Type" => "text/plain" }, e.message]
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
data/test/test_config_loader.rb
CHANGED
@@ -16,26 +16,26 @@ class TestConfigLoader < Minitest::Test
|
|
16
16
|
|
17
17
|
def test_highwater
|
18
18
|
assert_equal 0, @loader.highwater_mark
|
19
|
-
@loader.set(Prefab::
|
19
|
+
@loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]))
|
20
20
|
assert_equal 1, @loader.highwater_mark
|
21
21
|
|
22
|
-
@loader.set(Prefab::
|
22
|
+
@loader.set(Prefab::Config.new(id: 5, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]))
|
23
23
|
assert_equal 5, @loader.highwater_mark
|
24
|
-
@loader.set(Prefab::
|
24
|
+
@loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]))
|
25
25
|
assert_equal 5, @loader.highwater_mark
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_keeps_most_recent
|
29
29
|
assert_equal 0, @loader.highwater_mark
|
30
|
-
@loader.set(Prefab::
|
30
|
+
@loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 1))]))
|
31
31
|
assert_equal 1, @loader.highwater_mark
|
32
32
|
should_be :int, 1, "sample_int"
|
33
33
|
|
34
|
-
@loader.set(Prefab::
|
34
|
+
@loader.set(Prefab::Config.new(id: 4, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 4))]))
|
35
35
|
assert_equal 4, @loader.highwater_mark
|
36
36
|
should_be :int, 4, "sample_int"
|
37
37
|
|
38
|
-
@loader.set(Prefab::
|
38
|
+
@loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 2))]))
|
39
39
|
assert_equal 4, @loader.highwater_mark
|
40
40
|
should_be :int, 4, "sample_int"
|
41
41
|
end
|
@@ -43,37 +43,37 @@ class TestConfigLoader < Minitest::Test
|
|
43
43
|
def test_api_precedence
|
44
44
|
should_be :int, 123, "sample_int"
|
45
45
|
|
46
|
-
@loader.set(Prefab::
|
46
|
+
@loader.set(Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]))
|
47
47
|
should_be :int, 456, "sample_int"
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_api_deltas
|
51
51
|
val = Prefab::ConfigValue.new(int: 456)
|
52
|
-
|
53
|
-
@loader.set(
|
52
|
+
config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)])
|
53
|
+
@loader.set(config)
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
assert_equal
|
55
|
+
configs = Prefab::Configs.new
|
56
|
+
configs.configs << config
|
57
|
+
assert_equal configs, @loader.get_api_deltas
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_loading_tombstones_removes_entries
|
61
61
|
val = Prefab::ConfigValue.new(int: 456)
|
62
|
-
|
63
|
-
@loader.set(
|
62
|
+
config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)])
|
63
|
+
@loader.set(config)
|
64
64
|
|
65
|
-
|
66
|
-
@loader.set(
|
65
|
+
config = Prefab::Config.new(key: "sample_int", rows: [])
|
66
|
+
@loader.set(config)
|
67
67
|
|
68
|
-
|
69
|
-
assert_equal
|
68
|
+
configs = Prefab::Configs.new
|
69
|
+
assert_equal configs, @loader.get_api_deltas
|
70
70
|
end
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def should_be(type, value, key)
|
75
|
-
assert_equal type, @loader.calc_config[key].
|
76
|
-
assert_equal value, @loader.calc_config[key].
|
75
|
+
assert_equal type, @loader.calc_config[key].rows[0].value.type
|
76
|
+
assert_equal value, @loader.calc_config[key].rows[0].value.send(type)
|
77
77
|
end
|
78
78
|
|
79
79
|
end
|
@@ -2,45 +2,58 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class TestConfigResolver < Minitest::Test
|
4
4
|
|
5
|
+
STAGING_ENV_ID = 1
|
6
|
+
PRODUCTION_ENV_ID = 2
|
7
|
+
TEST_ENV_ID = 3
|
8
|
+
|
5
9
|
def test_resolution
|
6
10
|
@loader = MockConfigLoader.new
|
7
11
|
|
8
12
|
loaded_values = {
|
9
|
-
"key" => Prefab::
|
13
|
+
"key" => Prefab::Config.new(
|
10
14
|
key: "key",
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
15
|
+
rows: [
|
16
|
+
Prefab::ConfigRow.new(
|
17
|
+
value: Prefab::ConfigValue.new(string: "value_no_env_default"),
|
18
|
+
),
|
19
|
+
Prefab::ConfigRow.new(
|
20
|
+
project_env_id: TEST_ENV_ID,
|
21
|
+
value: Prefab::ConfigValue.new(string: "value_none"),
|
22
|
+
),
|
23
|
+
Prefab::ConfigRow.new(
|
24
|
+
project_env_id: TEST_ENV_ID,
|
25
|
+
namespace: "projectA",
|
26
|
+
value: Prefab::ConfigValue.new(string: "valueA"),
|
27
|
+
),
|
28
|
+
Prefab::ConfigRow.new(
|
29
|
+
project_env_id: TEST_ENV_ID,
|
30
|
+
namespace: "projectB",
|
31
|
+
value: Prefab::ConfigValue.new(string: "valueB"),
|
32
|
+
),
|
33
|
+
Prefab::ConfigRow.new(
|
34
|
+
project_env_id: TEST_ENV_ID,
|
35
|
+
namespace: "projectB.subprojectX",
|
36
|
+
value: Prefab::ConfigValue.new(string: "projectB.subprojectX"),
|
37
|
+
),
|
38
|
+
Prefab::ConfigRow.new(
|
39
|
+
project_env_id: TEST_ENV_ID,
|
40
|
+
namespace: "projectB.subprojectY",
|
41
|
+
value: Prefab::ConfigValue.new(string: "projectB.subprojectY"),
|
42
|
+
),
|
43
|
+
|
44
|
+
]
|
34
45
|
),
|
35
|
-
"key2" => Prefab::
|
46
|
+
"key2" => Prefab::Config.new(
|
36
47
|
key: "key2",
|
37
|
-
|
48
|
+
rows: [
|
49
|
+
value: Prefab::ConfigValue.new(string: "valueB2"),
|
50
|
+
]
|
38
51
|
)
|
39
52
|
}
|
40
53
|
|
41
54
|
@loader.stub :calc_config, loaded_values do
|
42
55
|
|
43
|
-
@resolverA = resolver_for_namespace("", @loader,
|
56
|
+
@resolverA = resolver_for_namespace("", @loader, project_env_id: PRODUCTION_ENV_ID)
|
44
57
|
assert_equal "value_no_env_default", @resolverA.get("key")
|
45
58
|
|
46
59
|
## below here in the test env
|
@@ -91,34 +104,34 @@ class TestConfigResolver < Minitest::Test
|
|
91
104
|
end
|
92
105
|
|
93
106
|
def test_special_ff_variant_copying
|
107
|
+
|
94
108
|
@loader = MockConfigLoader.new
|
95
109
|
loaded_values = {
|
96
|
-
"ff" => Prefab::
|
110
|
+
"ff" => Prefab::Config.new(
|
97
111
|
key: "ff",
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
default: Prefab::ConfigValue.new(feature_flag: Prefab::FeatureFlag.new(
|
112
|
+
variants: [
|
113
|
+
Prefab::FeatureFlagVariant.new(string: "inactive"),
|
114
|
+
Prefab::FeatureFlagVariant.new(string: "default"),
|
115
|
+
Prefab::FeatureFlagVariant.new(string: "env"),
|
116
|
+
],
|
117
|
+
rows: [
|
118
|
+
{ value: Prefab::ConfigValue.new(feature_flag: Prefab::FeatureFlag.new(
|
119
|
+
inactive_variant_idx: 0,
|
120
|
+
rules: default_ff_rule(1),
|
121
|
+
)) },
|
122
|
+
{ project_env_id: TEST_ENV_ID,
|
123
|
+
value: Prefab::ConfigValue.new(feature_flag: Prefab::FeatureFlag.new(
|
111
124
|
inactive_variant_idx: 0,
|
112
|
-
|
113
|
-
|
125
|
+
rules: default_ff_rule(2),
|
126
|
+
)) }
|
114
127
|
]
|
115
128
|
)
|
116
129
|
}
|
117
130
|
@loader.stub :calc_config, loaded_values do
|
118
131
|
resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
|
119
|
-
|
120
|
-
assert_equal 3,
|
121
|
-
assert_equal %w(inactive default env),
|
132
|
+
config = resolver.get_config("ff")
|
133
|
+
assert_equal 3, config.variants.size
|
134
|
+
assert_equal %w(inactive default env), config.variants.map(&:string)
|
122
135
|
end
|
123
136
|
end
|
124
137
|
|
@@ -127,13 +140,17 @@ class TestConfigResolver < Minitest::Test
|
|
127
140
|
@loader = MockConfigLoader.new
|
128
141
|
|
129
142
|
loaded_values = {
|
130
|
-
"Key:With:Colons" => Prefab::
|
143
|
+
"Key:With:Colons" => Prefab::Config.new(
|
131
144
|
key: "Key:With:Colons",
|
132
|
-
|
145
|
+
rows: [Prefab::ConfigRow.new(
|
146
|
+
value: Prefab::ConfigValue.new(string: "value")
|
147
|
+
)]
|
133
148
|
),
|
134
|
-
"proj:apikey" => Prefab::
|
149
|
+
"proj:apikey" => Prefab::Config.new(
|
135
150
|
key: "proj:apikey",
|
136
|
-
|
151
|
+
rows: [Prefab::ConfigRow.new(
|
152
|
+
value: Prefab::ConfigValue.new(string: "v2")
|
153
|
+
)]
|
137
154
|
)
|
138
155
|
}
|
139
156
|
|
@@ -171,8 +188,11 @@ class TestConfigResolver < Minitest::Test
|
|
171
188
|
end
|
172
189
|
end
|
173
190
|
|
174
|
-
def resolver_for_namespace(namespace, loader,
|
175
|
-
Prefab::ConfigResolver.new(MockBaseClient.new(namespace: namespace
|
191
|
+
def resolver_for_namespace(namespace, loader, project_env_id: TEST_ENV_ID)
|
192
|
+
resolver = Prefab::ConfigResolver.new(MockBaseClient.new(namespace: namespace), loader)
|
193
|
+
resolver.project_env_id = project_env_id
|
194
|
+
resolver.update
|
195
|
+
resolver
|
176
196
|
end
|
177
197
|
|
178
198
|
end
|