prefab-cloud-ruby 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/Gemfile +4 -11
  4. data/Gemfile.lock +32 -52
  5. data/README.md +1 -19
  6. data/Rakefile +0 -1
  7. data/VERSION +1 -1
  8. data/compile_protos.sh +0 -3
  9. data/lib/prefab/auth_interceptor.rb +0 -1
  10. data/lib/prefab/cancellable_interceptor.rb +0 -1
  11. data/lib/prefab/client.rb +36 -49
  12. data/lib/prefab/config_client.rb +73 -145
  13. data/lib/prefab/config_loader.rb +13 -98
  14. data/lib/prefab/config_resolver.rb +49 -56
  15. data/lib/prefab/feature_flag_client.rb +11 -129
  16. data/lib/prefab/logger_client.rb +8 -10
  17. data/lib/prefab/murmer3.rb +0 -1
  18. data/lib/prefab/noop_cache.rb +0 -1
  19. data/lib/prefab/noop_stats.rb +0 -1
  20. data/lib/prefab/ratelimit_client.rb +0 -1
  21. data/lib/prefab-cloud-ruby.rb +0 -10
  22. data/lib/prefab_pb.rb +132 -214
  23. data/lib/prefab_services_pb.rb +6 -35
  24. data/prefab-cloud-ruby.gemspec +11 -30
  25. data/test/.prefab.test.config.yaml +1 -27
  26. data/test/test_config_loader.rb +25 -39
  27. data/test/test_config_resolver.rb +38 -134
  28. data/test/test_feature_flag_client.rb +35 -277
  29. data/test/test_helper.rb +4 -70
  30. data/test/test_logger.rb +29 -23
  31. metadata +15 -70
  32. data/.github/workflows/ruby.yml +0 -39
  33. data/.tool-versions +0 -1
  34. data/CODEOWNERS +0 -1
  35. data/lib/prefab/config_helper.rb +0 -29
  36. data/lib/prefab/error.rb +0 -6
  37. data/lib/prefab/errors/initialization_timeout_error.rb +0 -13
  38. data/lib/prefab/errors/invalid_api_key_error.rb +0 -19
  39. data/lib/prefab/errors/missing_default_error.rb +0 -13
  40. data/lib/prefab/internal_logger.rb +0 -29
  41. data/lib/prefab/options.rb +0 -82
  42. data/run_test_harness_server.sh +0 -8
  43. data/test/harness_server.rb +0 -64
  44. data/test/test_client.rb +0 -91
  45. data/test/test_config_client.rb +0 -56
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
  # Generated by the protocol buffer compiler. DO NOT EDIT!
3
2
  # Source: prefab.proto for package 'prefab'
4
3
 
@@ -9,13 +8,13 @@ module Prefab
9
8
  module RateLimitService
10
9
  class Service
11
10
 
12
- include ::GRPC::GenericService
11
+ include GRPC::GenericService
13
12
 
14
13
  self.marshal_class_method = :encode
15
14
  self.unmarshal_class_method = :decode
16
15
  self.service_name = 'prefab.RateLimitService'
17
16
 
18
- rpc :LimitCheck, ::Prefab::LimitRequest, ::Prefab::LimitResponse
17
+ rpc :LimitCheck, LimitRequest, LimitResponse
19
18
  end
20
19
 
21
20
  Stub = Service.rpc_stub_class
@@ -23,43 +22,15 @@ module Prefab
23
22
  module ConfigService
24
23
  class Service
25
24
 
26
- include ::GRPC::GenericService
25
+ include GRPC::GenericService
27
26
 
28
27
  self.marshal_class_method = :encode
29
28
  self.unmarshal_class_method = :decode
30
29
  self.service_name = 'prefab.ConfigService'
31
30
 
32
- rpc :GetConfig, ::Prefab::ConfigServicePointer, stream(::Prefab::Configs)
33
- rpc :GetAllConfig, ::Prefab::ConfigServicePointer, ::Prefab::Configs
34
- rpc :Upsert, ::Prefab::Config, ::Prefab::CreationResponse
35
- end
36
-
37
- Stub = Service.rpc_stub_class
38
- end
39
- module IdService
40
- class Service
41
-
42
- include ::GRPC::GenericService
43
-
44
- self.marshal_class_method = :encode
45
- self.unmarshal_class_method = :decode
46
- self.service_name = 'prefab.IdService'
47
-
48
- rpc :GetBlock, ::Prefab::IdBlockRequest, ::Prefab::IdBlock
49
- end
50
-
51
- Stub = Service.rpc_stub_class
52
- end
53
- module ClientService
54
- class Service
55
-
56
- include ::GRPC::GenericService
57
-
58
- self.marshal_class_method = :encode
59
- self.unmarshal_class_method = :decode
60
- self.service_name = 'prefab.ClientService'
61
-
62
- rpc :GetAll, ::Prefab::Identity, ::Prefab::ConfigEvaluations
31
+ rpc :GetConfig, ConfigServicePointer, stream(ConfigDeltas)
32
+ rpc :GetAllConfig, ConfigServicePointer, ConfigDeltas
33
+ rpc :Upsert, UpsertRequest, ConfigServicePointer
63
34
  end
64
35
 
65
36
  Stub = Service.rpc_stub_class
@@ -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.13.0 ruby lib
5
+ # stub: prefab-cloud-ruby 0.13.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "prefab-cloud-ruby".freeze
9
- s.version = "0.13.0"
9
+ s.version = "0.13.1"
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-08-10"
14
+ s.date = "2022-08-12"
15
15
  s.description = "RateLimits & Config as a service".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.extra_rdoc_files = [
@@ -20,9 +20,7 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".envrc",
23
- ".github/workflows/ruby.yml",
24
- ".tool-versions",
25
- "CODEOWNERS",
23
+ ".ruby-version",
26
24
  "Gemfile",
27
25
  "Gemfile.lock",
28
26
  "LICENSE.txt",
@@ -35,29 +33,18 @@ Gem::Specification.new do |s|
35
33
  "lib/prefab/cancellable_interceptor.rb",
36
34
  "lib/prefab/client.rb",
37
35
  "lib/prefab/config_client.rb",
38
- "lib/prefab/config_helper.rb",
39
36
  "lib/prefab/config_loader.rb",
40
37
  "lib/prefab/config_resolver.rb",
41
- "lib/prefab/error.rb",
42
- "lib/prefab/errors/initialization_timeout_error.rb",
43
- "lib/prefab/errors/invalid_api_key_error.rb",
44
- "lib/prefab/errors/missing_default_error.rb",
45
38
  "lib/prefab/feature_flag_client.rb",
46
- "lib/prefab/internal_logger.rb",
47
39
  "lib/prefab/logger_client.rb",
48
40
  "lib/prefab/murmer3.rb",
49
41
  "lib/prefab/noop_cache.rb",
50
42
  "lib/prefab/noop_stats.rb",
51
- "lib/prefab/options.rb",
52
43
  "lib/prefab/ratelimit_client.rb",
53
44
  "lib/prefab_pb.rb",
54
45
  "lib/prefab_services_pb.rb",
55
46
  "prefab-cloud-ruby.gemspec",
56
- "run_test_harness_server.sh",
57
47
  "test/.prefab.test.config.yaml",
58
- "test/harness_server.rb",
59
- "test/test_client.rb",
60
- "test/test_config_client.rb",
61
48
  "test/test_config_loader.rb",
62
49
  "test/test_config_resolver.rb",
63
50
  "test/test_feature_flag_client.rb",
@@ -66,7 +53,7 @@ Gem::Specification.new do |s|
66
53
  ]
67
54
  s.homepage = "http://github.com/prefab-cloud/prefab-cloud-ruby".freeze
68
55
  s.licenses = ["MIT".freeze]
69
- s.rubygems_version = "3.2.32".freeze
56
+ s.rubygems_version = "3.1.6".freeze
70
57
  s.summary = "Prefab Ruby Infrastructure".freeze
71
58
 
72
59
  if s.respond_to? :specification_version then
@@ -76,29 +63,23 @@ Gem::Specification.new do |s|
76
63
  if s.respond_to? :add_runtime_dependency then
77
64
  s.add_runtime_dependency(%q<concurrent-ruby>.freeze, ["~> 1.0", ">= 1.0.5"])
78
65
  s.add_runtime_dependency(%q<faraday>.freeze, [">= 0"])
79
- s.add_runtime_dependency(%q<ld-eventsource>.freeze, [">= 0"])
80
66
  s.add_runtime_dependency(%q<grpc>.freeze, [">= 0"])
81
- s.add_runtime_dependency(%q<google-protobuf>.freeze, [">= 0"])
82
- s.add_runtime_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
83
- s.add_development_dependency(%q<grpc-tools>.freeze, [">= 0"])
67
+ s.add_development_dependency(%q<grpc-tools>.freeze, ["~> 1.17.1"])
68
+ s.add_development_dependency(%q<shoulda>.freeze, [">= 0"])
84
69
  s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
85
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
70
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
86
71
  s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.4.9"])
87
72
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
88
- s.add_development_dependency(%q<thin>.freeze, [">= 0"])
89
73
  else
90
74
  s.add_dependency(%q<concurrent-ruby>.freeze, ["~> 1.0", ">= 1.0.5"])
91
75
  s.add_dependency(%q<faraday>.freeze, [">= 0"])
92
- s.add_dependency(%q<ld-eventsource>.freeze, [">= 0"])
93
76
  s.add_dependency(%q<grpc>.freeze, [">= 0"])
94
- s.add_dependency(%q<google-protobuf>.freeze, [">= 0"])
95
- s.add_dependency(%q<googleapis-common-protos-types>.freeze, [">= 0"])
96
- s.add_dependency(%q<grpc-tools>.freeze, [">= 0"])
77
+ s.add_dependency(%q<grpc-tools>.freeze, ["~> 1.17.1"])
78
+ s.add_dependency(%q<shoulda>.freeze, [">= 0"])
97
79
  s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
98
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
80
+ s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
99
81
  s.add_dependency(%q<juwelier>.freeze, ["~> 2.4.9"])
100
82
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
101
- s.add_dependency(%q<thin>.freeze, [">= 0"])
102
83
  end
103
84
  end
104
85
 
@@ -1,32 +1,6 @@
1
- sample: default sample value
1
+ sample: OneTwoThree
2
2
  sample_int: 123
3
3
  sample_double: 12.12
4
4
  sample_bool: true
5
- false_value: false
6
- zero_value: 0
7
5
  sample_to_override: Foo
8
6
  prefab.log_level: debug
9
- unit_tests:
10
- sample: test sample value
11
- enabled_flag: true
12
- disabled_flag: false
13
- flag_with_a_value:
14
- feature_flag: true
15
- value: "all-features"
16
- in_lookup_key:
17
- feature_flag: true
18
- value: true
19
- criteria:
20
- operator: LOOKUP_KEY_IN
21
- values:
22
- - abc123
23
- - xyz987
24
- just_my_domain:
25
- feature_flag: true
26
- value: new-version
27
- criteria:
28
- operator: PROP_IS_ONE_OF
29
- property: domain
30
- values: ["prefab.cloud", "example.com"]
31
- ignored_env:
32
- sample: ignored value
@@ -1,56 +1,41 @@
1
- # frozen_string_literal: true
2
1
  require 'test_helper'
3
2
 
4
3
  class TestConfigLoader < Minitest::Test
5
4
  def setup
6
- options = Prefab::Options.new(
7
- prefab_config_override_dir: "none",
8
- prefab_config_classpath_dir: "test",
9
- defaults_env: "unit_tests"
10
- )
11
- @loader = Prefab::ConfigLoader.new(MockBaseClient.new(options))
5
+ ENV['PREFAB_CONFIG_OVERRIDE_DIR'] = "none"
6
+ ENV['PREFAB_CONFIG_CLASSPATH_DIR'] = "test"
7
+ @loader = Prefab::ConfigLoader.new(MockBaseClient.new)
12
8
  end
13
9
 
14
10
  def test_load
15
11
  should_be :int, 123, "sample_int"
16
- should_be :string, "test sample value", "sample"
12
+ should_be :string, "OneTwoThree", "sample"
17
13
  should_be :bool, true, "sample_bool"
18
14
  should_be :double, 12.12, "sample_double"
19
15
  end
20
16
 
21
- def test_load_in_no_default_env
22
- options = Prefab::Options.new(
23
- prefab_config_override_dir: "none",
24
- prefab_config_classpath_dir: "test",
25
- # no defaults_env
26
- )
27
- @loader = Prefab::ConfigLoader.new(MockBaseClient.new(options))
28
- should_be :string, "default sample value", "sample"
29
- should_be :bool, true, "sample_bool"
30
- end
31
-
32
17
  def test_highwater
33
18
  assert_equal 0, @loader.highwater_mark
34
- @loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
19
+ @loader.set(Prefab::ConfigDelta.new(id: 1, key: "sample_int", value: Prefab::ConfigValue.new(int: 456)))
35
20
  assert_equal 1, @loader.highwater_mark
36
21
 
37
- @loader.set(Prefab::Config.new(id: 5, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
22
+ @loader.set(Prefab::ConfigDelta.new(id: 5, key: "sample_int", value: Prefab::ConfigValue.new(int: 456)))
38
23
  assert_equal 5, @loader.highwater_mark
39
- @loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
24
+ @loader.set(Prefab::ConfigDelta.new(id: 2, key: "sample_int", value: Prefab::ConfigValue.new(int: 456)))
40
25
  assert_equal 5, @loader.highwater_mark
41
26
  end
42
27
 
43
28
  def test_keeps_most_recent
44
29
  assert_equal 0, @loader.highwater_mark
45
- @loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 1))]),"test")
30
+ @loader.set(Prefab::ConfigDelta.new(id: 1, key: "sample_int", value: Prefab::ConfigValue.new(int: 1)))
46
31
  assert_equal 1, @loader.highwater_mark
47
32
  should_be :int, 1, "sample_int"
48
33
 
49
- @loader.set(Prefab::Config.new(id: 4, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 4))]),"test")
34
+ @loader.set(Prefab::ConfigDelta.new(id: 4, key: "sample_int", value: Prefab::ConfigValue.new(int: 4)))
50
35
  assert_equal 4, @loader.highwater_mark
51
36
  should_be :int, 4, "sample_int"
52
37
 
53
- @loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 2))]),"test")
38
+ @loader.set(Prefab::ConfigDelta.new(id: 2, key: "sample_int", value: Prefab::ConfigValue.new(int: 2)))
54
39
  assert_equal 4, @loader.highwater_mark
55
40
  should_be :int, 4, "sample_int"
56
41
  end
@@ -58,36 +43,37 @@ class TestConfigLoader < Minitest::Test
58
43
  def test_api_precedence
59
44
  should_be :int, 123, "sample_int"
60
45
 
61
- @loader.set(Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]), "test")
46
+ @loader.set(Prefab::ConfigDelta.new(key: "sample_int", value: Prefab::ConfigValue.new(int: 456)))
62
47
  should_be :int, 456, "sample_int"
63
48
  end
64
49
 
65
50
  def test_api_deltas
66
51
  val = Prefab::ConfigValue.new(int: 456)
67
- config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)])
68
- @loader.set(config, "test")
52
+ delta = Prefab::ConfigDelta.new(key: "sample_int", value: val)
53
+ @loader.set(delta)
69
54
 
70
- configs = Prefab::Configs.new
71
- configs.configs << config
72
- assert_equal configs, @loader.get_api_deltas
55
+ deltas = Prefab::ConfigDeltas.new
56
+ deltas.deltas << delta
57
+ assert_equal deltas, @loader.get_api_deltas
73
58
  end
74
59
 
75
60
  def test_loading_tombstones_removes_entries
76
61
  val = Prefab::ConfigValue.new(int: 456)
77
- config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)], id: 2)
78
- @loader.set(config, "test")
62
+ delta = Prefab::ConfigDelta.new(key: "sample_int", value: val)
63
+ @loader.set(delta)
79
64
 
80
- config = Prefab::Config.new(key: "sample_int", rows: [], id: 3)
81
- @loader.set(config, "test")
65
+ delta = Prefab::ConfigDelta.new(key: "sample_int", value: nil)
66
+ @loader.set(delta)
82
67
 
83
- configs = Prefab::Configs.new
84
- assert_equal configs, @loader.get_api_deltas
68
+ deltas = Prefab::ConfigDeltas.new
69
+ assert_equal deltas, @loader.get_api_deltas
85
70
  end
86
71
 
87
72
  private
88
73
 
89
74
  def should_be(type, value, key)
90
- assert_equal type, @loader.calc_config[key][:config].rows[0].value.type
91
- assert_equal value, @loader.calc_config[key][:config].rows[0].value.send(type)
75
+ assert_equal type, @loader.calc_config[key].type
76
+ assert_equal value, @loader.calc_config[key].send(type)
92
77
  end
78
+
93
79
  end
@@ -1,66 +1,22 @@
1
- # frozen_string_literal: true
2
1
  require 'test_helper'
3
2
 
4
3
  class TestConfigResolver < Minitest::Test
5
4
 
6
- STAGING_ENV_ID = 1
7
- PRODUCTION_ENV_ID = 2
8
- TEST_ENV_ID = 3
9
-
10
5
  def test_resolution
11
6
  @loader = MockConfigLoader.new
12
7
 
13
8
  loaded_values = {
14
- "key" => { config: Prefab::Config.new(
15
- key: "key",
16
- rows: [
17
- Prefab::ConfigRow.new(
18
- value: Prefab::ConfigValue.new(string: "value_no_env_default"),
19
- ),
20
- Prefab::ConfigRow.new(
21
- project_env_id: TEST_ENV_ID,
22
- value: Prefab::ConfigValue.new(string: "value_none"),
23
- ),
24
- Prefab::ConfigRow.new(
25
- project_env_id: TEST_ENV_ID,
26
- namespace: "projectA",
27
- value: Prefab::ConfigValue.new(string: "valueA"),
28
- ),
29
- Prefab::ConfigRow.new(
30
- project_env_id: TEST_ENV_ID,
31
- namespace: "projectB",
32
- value: Prefab::ConfigValue.new(string: "valueB"),
33
- ),
34
- Prefab::ConfigRow.new(
35
- project_env_id: TEST_ENV_ID,
36
- namespace: "projectB.subprojectX",
37
- value: Prefab::ConfigValue.new(string: "projectB.subprojectX"),
38
- ),
39
- Prefab::ConfigRow.new(
40
- project_env_id: TEST_ENV_ID,
41
- namespace: "projectB.subprojectY",
42
- value: Prefab::ConfigValue.new(string: "projectB.subprojectY"),
43
- ),
44
-
45
- ]
46
- ) },
47
- "key2" => { config: Prefab::Config.new(
48
- key: "key2",
49
- rows: [
50
- value: Prefab::ConfigValue.new(string: "valueB2"),
51
- ]
52
- ) }
53
-
9
+ "projectA:key" => Prefab::ConfigValue.new(string: "valueA"),
10
+ "key" => Prefab::ConfigValue.new(string: "value_none"),
11
+ "projectB:key" => Prefab::ConfigValue.new(string: "valueB"),
12
+ "projectB.subprojectX:key" => Prefab::ConfigValue.new(string: "projectB.subprojectX"),
13
+ "projectB.subprojectY:key" => Prefab::ConfigValue.new(string: "projectB.subprojectY"),
14
+ "projectB:key2" => Prefab::ConfigValue.new(string: "valueB2")
54
15
  }
55
16
 
56
17
  @loader.stub :calc_config, loaded_values do
57
-
58
- @resolverA = resolver_for_namespace("", @loader, project_env_id: PRODUCTION_ENV_ID)
59
- assert_equal "value_no_env_default", @resolverA.get("key")
60
-
61
- ## below here in the test env
62
- @resolverA = resolver_for_namespace("", @loader)
63
- assert_equal "value_none", @resolverA.get("key")
18
+ @resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
19
+ assert_equal "value_none", @resolver.get("key")
64
20
 
65
21
  @resolverA = resolver_for_namespace("projectA", @loader)
66
22
  assert_equal "valueA", @resolverA.get("key")
@@ -71,10 +27,7 @@ class TestConfigResolver < Minitest::Test
71
27
  @resolverBX = resolver_for_namespace("projectB.subprojectX", @loader)
72
28
  assert_equal "projectB.subprojectX", @resolverBX.get("key")
73
29
 
74
- @resolverBX = resolver_for_namespace("projectB.subprojectX", @loader)
75
- assert_equal "valueB2", @resolverBX.get("key2")
76
-
77
- @resolverUndefinedSubProject = resolver_for_namespace("projectB.subprojectX.subsubQ", @loader)
30
+ @resolverUndefinedSubProject = resolver_for_namespace("projectB.subprojectX:subsubQ", @loader)
78
31
  assert_equal "projectB.subprojectX", @resolverBX.get("key")
79
32
 
80
33
  @resolverBX = resolver_for_namespace("projectC", @loader)
@@ -87,75 +40,30 @@ class TestConfigResolver < Minitest::Test
87
40
  @loader = MockConfigLoader.new
88
41
  @loader.stub :calc_config, {} do
89
42
  resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
90
- assert_equal [true, 0], resolver.send(:starts_with_ns?, "", "a")
91
- assert_equal [true, 1], resolver.send(:starts_with_ns?, "a", "a")
92
- assert_equal [true, 1], resolver.send(:starts_with_ns?, "a", "a.b")
93
- assert_equal [false, 2], resolver.send(:starts_with_ns?, "a.b", "a")
94
-
95
- assert_equal [true, 1], resolver.send(:starts_with_ns?, "corp", "corp.proj.proja")
96
- assert_equal [true, 2], resolver.send(:starts_with_ns?, "corp.proj", "corp.proj.proja")
97
- assert_equal [true, 3], resolver.send(:starts_with_ns?, "corp.proj.proja", "corp.proj.proja")
98
- assert_equal [false, 3], resolver.send(:starts_with_ns?, "corp.proj.projb", "corp.proj.proja")
99
-
100
- # corp_equal [true, 1:,a:b is not a real delimited namespace[0
101
- assert_equal [false, 1], resolver.send(:starts_with_ns?, "corp", "corp:a:b")
102
- assert_equal [true, 1], resolver.send(:starts_with_ns?, "foo", "foo.baz")
103
- assert_equal [true, 2], resolver.send(:starts_with_ns?, "foo.baz", "foo.baz")
104
- assert_equal [false, 2], resolver.send(:starts_with_ns?, "foo.baz", "foo.bazz")
105
- end
106
- end
107
-
108
- def test_special_ff_variant_copying
109
-
110
- @loader = MockConfigLoader.new
111
- loaded_values = {
112
- "ff" => { source: 'test',
113
- config: Prefab::Config.new(
114
- key: "ff",
115
- variants: [
116
- Prefab::FeatureFlagVariant.new(string: "inactive"),
117
- Prefab::FeatureFlagVariant.new(string: "default"),
118
- Prefab::FeatureFlagVariant.new(string: "env"),
119
- ],
120
- rows: [
121
- { value: Prefab::ConfigValue.new(feature_flag: Prefab::FeatureFlag.new(
122
- inactive_variant_idx: 0,
123
- rules: default_ff_rule(1),
124
- )) },
125
- { project_env_id: TEST_ENV_ID,
126
- value: Prefab::ConfigValue.new(feature_flag: Prefab::FeatureFlag.new(
127
- inactive_variant_idx: 0,
128
- rules: default_ff_rule(2),
129
- )) }
130
- ]
131
- )
132
- }
133
- }
134
- @loader.stub :calc_config, loaded_values do
135
- resolver = Prefab::ConfigResolver.new(MockBaseClient.new, @loader)
136
- config = resolver.get_config("ff")
137
- assert_equal 3, config.variants.size
138
- assert_equal %w(inactive default env), config.variants.map(&:string)
43
+ assert resolver.send(:starts_with_ns?, "", "a")
44
+ assert resolver.send(:starts_with_ns?, "a", "a")
45
+ assert resolver.send(:starts_with_ns?, "a", "a.b")
46
+ assert !resolver.send(:starts_with_ns?, "a.b", "a")
47
+
48
+ assert resolver.send(:starts_with_ns?, "corp", "corp.proj.proja")
49
+ assert resolver.send(:starts_with_ns?, "corp.proj", "corp.proj.proja")
50
+ assert resolver.send(:starts_with_ns?, "corp.proj.proja", "corp.proj.proja")
51
+ assert !resolver.send(:starts_with_ns?, "corp.proj.projb", "corp.proj.proja")
52
+
53
+ # corp:a:b is not a real delimited namespace
54
+ assert !resolver.send(:starts_with_ns?, "corp", "corp:a:b")
55
+ assert resolver.send(:starts_with_ns?, "foo", "foo.baz")
56
+ assert resolver.send(:starts_with_ns?, "foo.baz", "foo.baz")
57
+ assert !resolver.send(:starts_with_ns?, "foo.baz", "foo.bazz")
139
58
  end
140
59
  end
141
60
 
142
61
  # colons are not allowed in keys, but verify behavior anyway
143
- def test_key_and_namespaces_with_colons
62
+ def test_keys_with_colons
144
63
  @loader = MockConfigLoader.new
145
-
146
64
  loaded_values = {
147
- "Key:With:Colons" => { config: Prefab::Config.new(
148
- key: "Key:With:Colons",
149
- rows: [Prefab::ConfigRow.new(
150
- value: Prefab::ConfigValue.new(string: "value")
151
- )]
152
- ) },
153
- "proj:apikey" => { config: Prefab::Config.new(
154
- key: "proj:apikey",
155
- rows: [Prefab::ConfigRow.new(
156
- value: Prefab::ConfigValue.new(string: "v2")
157
- )]
158
- ) }
65
+ "Key:With:Colons" => Prefab::ConfigValue.new(string: "value"),
66
+ "proj:apikey" => Prefab::ConfigValue.new(string: "v2")
159
67
  }
160
68
 
161
69
  @loader.stub :calc_config, loaded_values do
@@ -164,41 +72,37 @@ class TestConfigResolver < Minitest::Test
164
72
  assert_nil r.get("apikey")
165
73
 
166
74
  r = resolver_for_namespace("proj", @loader)
167
- assert_nil r.get("apikey")
75
+ assert_equal "v2", r.get("apikey")
168
76
 
169
77
  r = resolver_for_namespace("", @loader)
170
78
  assert_nil r.get("apikey")
171
79
 
80
+
172
81
  @resolverKeyWith = resolver_for_namespace("Ket:With", @loader)
173
82
  assert_nil @resolverKeyWith.get("Colons")
174
83
  assert_nil @resolverKeyWith.get("With:Colons")
175
- assert_equal "value", @resolverKeyWith.get("Key:With:Colons")
84
+ assert_nil @resolverKeyWith.get("Key:With:Colons")
176
85
 
177
86
  @resolverKeyWithExtra = resolver_for_namespace("Key:With:Extra", @loader)
87
+ puts @resolverKeyWithExtra.to_s
178
88
  assert_nil @resolverKeyWithExtra.get("Colons")
179
89
  assert_nil @resolverKeyWithExtra.get("With:Colons")
180
- assert_equal "value", @resolverKeyWithExtra.get("Key:With:Colons")
90
+ assert_nil @resolverKeyWithExtra.get("Key:With:Colons")
181
91
 
182
92
  @resolverKey = resolver_for_namespace("Key", @loader)
183
- assert_nil @resolverKey.get("With:Colons")
93
+ assert_equal "value", @resolverKey.get("With:Colons")
184
94
  assert_nil @resolverKey.get("Colons")
185
- assert_equal "value", @resolverKey.get("Key:With:Colons")
95
+ assert_nil @resolverKey.get("Key:With:Colons")
186
96
 
187
97
  @resolverWithProperlySegmentedNamespace = resolver_for_namespace("Key.With.Extra", @loader)
188
98
  assert_nil @resolverWithProperlySegmentedNamespace.get("Colons")
189
- assert_nil @resolverWithProperlySegmentedNamespace.get("With:Colons")
190
- assert_equal "value", @resolverWithProperlySegmentedNamespace.get("Key:With:Colons")
99
+ assert_equal "value", @resolverWithProperlySegmentedNamespace.get("With:Colons")
100
+ assert_nil @resolverWithProperlySegmentedNamespace.get("Key:With:Colons")
191
101
  end
192
102
  end
193
103
 
194
- def resolver_for_namespace(namespace, loader, project_env_id: TEST_ENV_ID)
195
- options = Prefab::Options.new(
196
- namespace: namespace
197
- )
198
- resolver = Prefab::ConfigResolver.new(MockBaseClient.new(options), loader)
199
- resolver.project_env_id = project_env_id
200
- resolver.update
201
- resolver
104
+ def resolver_for_namespace(namespace, loader)
105
+ Prefab::ConfigResolver.new(MockBaseClient.new(namespace: namespace), loader)
202
106
  end
203
107
 
204
108
  end