prefab-cloud-ruby 0.20.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc.sample +3 -0
  3. data/.github/workflows/ruby.yml +5 -1
  4. data/.gitmodules +3 -0
  5. data/Gemfile +14 -12
  6. data/Gemfile.lock +24 -14
  7. data/README.md +12 -10
  8. data/Rakefile +13 -14
  9. data/VERSION +1 -1
  10. data/lib/prefab/auth_interceptor.rb +2 -1
  11. data/lib/prefab/cancellable_interceptor.rb +8 -7
  12. data/lib/prefab/client.rb +52 -27
  13. data/lib/prefab/config_client.rb +59 -70
  14. data/lib/prefab/config_loader.rb +7 -114
  15. data/lib/prefab/config_resolver.rb +27 -57
  16. data/lib/prefab/config_value_unwrapper.rb +23 -0
  17. data/lib/prefab/criteria_evaluator.rb +96 -0
  18. data/lib/prefab/errors/invalid_api_key_error.rb +1 -1
  19. data/lib/prefab/feature_flag_client.rb +13 -145
  20. data/lib/prefab/internal_logger.rb +7 -6
  21. data/lib/prefab/local_config_parser.rb +110 -0
  22. data/lib/prefab/log_path_collector.rb +98 -0
  23. data/lib/prefab/logger_client.rb +46 -44
  24. data/lib/prefab/murmer3.rb +3 -4
  25. data/lib/prefab/noop_cache.rb +5 -7
  26. data/lib/prefab/noop_stats.rb +2 -3
  27. data/lib/prefab/options.rb +32 -11
  28. data/lib/prefab/ratelimit_client.rb +11 -13
  29. data/lib/prefab/sse_logger.rb +3 -2
  30. data/lib/prefab/weighted_value_resolver.rb +42 -0
  31. data/lib/prefab/yaml_config_parser.rb +32 -0
  32. data/lib/prefab-cloud-ruby.rb +7 -2
  33. data/lib/prefab_pb.rb +70 -43
  34. data/lib/prefab_services_pb.rb +14 -1
  35. data/prefab-cloud-ruby.gemspec +33 -19
  36. data/test/.prefab.unit_tests.config.yaml +3 -2
  37. data/test/integration_test.rb +98 -0
  38. data/test/integration_test_helpers.rb +37 -0
  39. data/test/test_client.rb +56 -31
  40. data/test/test_config_client.rb +21 -20
  41. data/test/test_config_loader.rb +48 -37
  42. data/test/test_config_resolver.rb +312 -135
  43. data/test/test_config_value_unwrapper.rb +83 -0
  44. data/test/test_criteria_evaluator.rb +533 -0
  45. data/test/test_feature_flag_client.rb +35 -347
  46. data/test/test_helper.rb +18 -14
  47. data/test/test_integration.rb +33 -0
  48. data/test/test_local_config_parser.rb +78 -0
  49. data/test/test_log_path_collector.rb +56 -0
  50. data/test/test_logger.rb +52 -51
  51. data/test/test_options.rb +32 -0
  52. data/test/test_weighted_value_resolver.rb +65 -0
  53. metadata +30 -16
  54. data/lib/prefab/config_helper.rb +0 -31
  55. data/run_test_harness_server.sh +0 -8
  56. data/test/harness_server.rb +0 -64
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IntegrationTest
4
+ attr_reader :func
5
+ attr_reader :input
6
+ attr_reader :expected
7
+ attr_reader :test_client
8
+
9
+ def initialize(test_data)
10
+ @client_overrides = parse_client_overrides(test_data['client_overrides'])
11
+ @func = parse_function(test_data['function'])
12
+ @input = parse_input(test_data['input'])
13
+ @expected = parse_expected(test_data['expected'])
14
+ test_client = :"#{test_data['client']}"
15
+ @test_client = base_client.send(test_client)
16
+ end
17
+
18
+ def test_type
19
+ if @expected[:status] == 'raise'
20
+ :raise
21
+ elsif @expected[:value].nil?
22
+ :nil
23
+ elsif @func == :feature_is_on_for?
24
+ :feature_flag
25
+ else
26
+ :simple_equality
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def parse_client_overrides(overrides)
33
+ Hash[
34
+ (overrides || {}).map do |(k, v)|
35
+ [k.to_sym, v]
36
+ end
37
+ ]
38
+ end
39
+
40
+ def parse_function(function)
41
+ case function
42
+ when 'get_or_raise' then :get
43
+ when 'enabled' then :feature_is_on_for?
44
+ else :"#{function}"
45
+ end
46
+ end
47
+
48
+ def parse_input(input)
49
+ if input['key']
50
+ parse_config_input(input)
51
+ elsif input['flag']
52
+ parse_ff_input(input)
53
+ end
54
+ end
55
+
56
+ def parse_config_input(input)
57
+ if !input['default'].nil?
58
+ [input['key'], input['default']]
59
+ else
60
+ [input['key']]
61
+ end
62
+ end
63
+
64
+ def parse_ff_input(input)
65
+ [input['flag'], input['lookup_key'], input['properties'] || {}]
66
+ end
67
+
68
+ def parse_expected(expected)
69
+ {
70
+ status: expected['status'],
71
+ error: parse_error_type(expected['error']),
72
+ message: expected['message'],
73
+ value: expected['value']
74
+ }
75
+ end
76
+
77
+ def parse_error_type(error_type)
78
+ case error_type
79
+ when 'missing_default' then Prefab::Errors::MissingDefaultError
80
+ end
81
+ end
82
+
83
+ def base_client
84
+ @_base_client ||= Prefab::Client.new(base_client_options)
85
+ end
86
+
87
+ def base_client_options
88
+ @_options ||= Prefab::Options.new(**{
89
+ prefab_config_override_dir: 'none',
90
+ prefab_config_classpath_dir: 'test',
91
+ prefab_envs: ['unit_tests'],
92
+ prefab_datasources: Prefab::Options::DATASOURCES::ALL,
93
+ api_key: ENV['PREFAB_INTEGRATION_TEST_API_KEY'],
94
+ prefab_api_url: 'https://api.staging-prefab.cloud',
95
+ prefab_grpc_url: 'grpc.staging-prefab.cloud:443'
96
+ }.merge(@client_overrides))
97
+ end
98
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IntegrationTestHelpers
4
+ SUBMODULE_PATH = 'test/prefab-cloud-integration-test-data'
5
+ RAISE_IF_NO_TESTS_FOUND = ENV['PREFAB_INTEGRATION_TEST_RAISE'] == 'true'
6
+
7
+ def self.find_integration_tests
8
+ version = find_integration_test_version
9
+
10
+ files = find_versioned_test_files(version)
11
+
12
+ if files.none?
13
+ message = "No integration tests found for version: #{version}"
14
+ raise message if RAISE_IF_NO_TESTS_FOUND
15
+
16
+ puts message
17
+
18
+ end
19
+
20
+ files
21
+ end
22
+
23
+ def self.find_integration_test_version
24
+ File.read(File.join(SUBMODULE_PATH, 'version')).strip
25
+ rescue StandardError => e
26
+ puts "No version found for integration tests: #{e.message}"
27
+ end
28
+
29
+ def self.find_versioned_test_files(version)
30
+ if version.nil?
31
+ []
32
+ else
33
+ Dir[File.join(SUBMODULE_PATH, "tests/#{version}/**/*")]
34
+ .select { |file| file =~ /\.ya?ml$/ }
35
+ end
36
+ end
37
+ end
data/test/test_client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class TestClient < Minitest::Test
@@ -7,25 +8,25 @@ class TestClient < Minitest::Test
7
8
  end
8
9
 
9
10
  def test_get
10
- assert_equal "test sample value", @client.get("sample")
11
- assert_equal 123, @client.get("sample_int")
11
+ assert_equal 'test sample value', @client.get('sample')
12
+ assert_equal 123, @client.get('sample_int')
12
13
  end
13
14
 
14
15
  def test_get_with_default
15
16
  # A `false` value is not replaced with the default
16
- assert_equal false, @client.get("false_value", "red")
17
+ assert_equal false, @client.get('false_value', 'red')
17
18
 
18
19
  # A falsy value is not replaced with the default
19
- assert_equal 0, @client.get("zero_value", "red")
20
+ assert_equal 0, @client.get('zero_value', 'red')
20
21
 
21
22
  # A missing value returns the default
22
- assert_equal "buckets", @client.get("missing_value", "buckets")
23
+ assert_equal 'buckets', @client.get('missing_value', 'buckets')
23
24
  end
24
25
 
25
26
  def test_get_with_missing_default
26
27
  # it raises by default
27
28
  err = assert_raises(Prefab::Errors::MissingDefaultError) do
28
- assert_nil @client.get("missing_value")
29
+ assert_nil @client.get('missing_value')
29
30
  end
30
31
 
31
32
  assert_match(/No value found for key/, err.message)
@@ -33,63 +34,87 @@ class TestClient < Minitest::Test
33
34
 
34
35
  # you can opt-in to return `nil` instead
35
36
  client = new_client(on_no_default: Prefab::Options::ON_NO_DEFAULT::RETURN_NIL)
36
- assert_nil client.get("missing_value")
37
+ assert_nil client.get('missing_value')
37
38
  end
38
39
 
39
40
  def test_enabled
40
- assert_equal false, @client.enabled?("does_not_exist")
41
- assert_equal true, @client.enabled?("enabled_flag")
42
- assert_equal false, @client.enabled?("disabled_flag")
43
- assert_equal false, @client.enabled?("flag_with_a_value")
41
+ assert_equal false, @client.enabled?('does_not_exist')
42
+ assert_equal true, @client.enabled?('enabled_flag')
43
+ assert_equal false, @client.enabled?('disabled_flag')
44
+ assert_equal false, @client.enabled?('flag_with_a_value')
44
45
  end
45
46
 
46
47
  def test_ff_enabled_with_lookup_key
47
- assert_equal false, @client.enabled?("in_lookup_key", "jimmy")
48
- assert_equal true, @client.enabled?("in_lookup_key", "abc123")
49
- assert_equal true, @client.enabled?("in_lookup_key", "xyz987")
48
+ assert_equal false, @client.enabled?('in_lookup_key', 'jimmy')
49
+ assert_equal true, @client.enabled?('in_lookup_key', 'abc123')
50
+ assert_equal true, @client.enabled?('in_lookup_key', 'xyz987')
50
51
  end
51
52
 
52
53
  def test_ff_get_with_lookup_key
53
- assert_nil @client.get("in_lookup_key", "jimmy")
54
- assert_equal "DEFAULT", @client.get("in_lookup_key", "jimmy", {}, "DEFAULT")
54
+ assert_nil @client.get('in_lookup_key', 'jimmy')
55
+ assert_equal 'DEFAULT', @client.get('in_lookup_key', 'jimmy', {}, 'DEFAULT')
55
56
 
56
- assert_equal true, @client.get("in_lookup_key", "abc123")
57
- assert_equal true, @client.get("in_lookup_key", "xyz987")
57
+ assert_equal true, @client.get('in_lookup_key', 'abc123')
58
+ assert_equal true, @client.get('in_lookup_key', 'xyz987')
58
59
  end
59
60
 
60
61
  def test_ff_enabled_with_attributes
61
- assert_equal false, @client.enabled?("just_my_domain", "abc123", { domain: "gmail.com" })
62
- assert_equal false, @client.enabled?("just_my_domain", "abc123", { domain: "prefab.cloud" })
63
- assert_equal false, @client.enabled?("just_my_domain", "abc123", { domain: "example.com" })
62
+ assert_equal false, @client.enabled?('just_my_domain', 'abc123', { domain: 'gmail.com' })
63
+ assert_equal false, @client.enabled?('just_my_domain', 'abc123', { domain: 'prefab.cloud' })
64
+ assert_equal false, @client.enabled?('just_my_domain', 'abc123', { domain: 'example.com' })
64
65
  end
65
66
 
66
67
  def test_ff_get_with_attributes
67
- assert_nil @client.get("just_my_domain", "abc123", { domain: "gmail.com" })
68
- assert_equal "DEFAULT", @client.get("just_my_domain", "abc123", { domain: "gmail.com" }, "DEFAULT")
68
+ assert_nil @client.get('just_my_domain', 'abc123', { domain: 'gmail.com' })
69
+ assert_equal 'DEFAULT', @client.get('just_my_domain', 'abc123', { domain: 'gmail.com' }, 'DEFAULT')
69
70
 
70
- assert_equal "new-version", @client.get("just_my_domain", "abc123", { domain: "prefab.cloud" })
71
- assert_equal "new-version", @client.get("just_my_domain", "abc123", { domain: "example.com" })
71
+ assert_equal 'new-version', @client.get('just_my_domain', 'abc123', { domain: 'prefab.cloud' })
72
+ assert_equal 'new-version', @client.get('just_my_domain', 'abc123', { domain: 'example.com' })
72
73
  end
73
74
 
74
75
  def test_getting_feature_flag_value
75
- assert_equal false, @client.enabled?("flag_with_a_value")
76
- assert_equal "all-features", @client.get("flag_with_a_value")
76
+ assert_equal false, @client.enabled?('flag_with_a_value')
77
+ assert_equal 'all-features', @client.get('flag_with_a_value')
77
78
  end
78
79
 
79
80
  def test_ssl_certs
80
- certs = @client.send(:ssl_certs).split("-----BEGIN CERTIFICATE-----")
81
+ certs = @client.send(:ssl_certs).split('-----BEGIN CERTIFICATE-----')
81
82
 
82
83
  # This is a smoke test to make sure multiple certs are loaded
83
84
  assert certs.length > 1
84
85
  end
85
86
 
87
+ def test_initialization_with_an_options_object
88
+ options_hash = {
89
+ namespace: 'test-namespace',
90
+ prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
91
+ }
92
+
93
+ options = Prefab::Options.new(options_hash)
94
+
95
+ client = Prefab::Client.new(options)
96
+
97
+ assert_equal client.namespace, 'test-namespace'
98
+ end
99
+
100
+ def test_initialization_with_a_hash
101
+ options_hash = {
102
+ namespace: 'test-namespace',
103
+ prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
104
+ }
105
+
106
+ client = Prefab::Client.new(options_hash)
107
+
108
+ assert_equal client.namespace, 'test-namespace'
109
+ end
110
+
86
111
  private
87
112
 
88
113
  def new_client(overrides = {})
89
114
  options = Prefab::Options.new(**{
90
- prefab_config_override_dir: "none",
91
- prefab_config_classpath_dir: "test",
92
- prefab_envs: ["unit_tests"],
115
+ prefab_config_override_dir: 'none',
116
+ prefab_config_classpath_dir: 'test',
117
+ prefab_envs: ['unit_tests'],
93
118
  prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
94
119
  }.merge(overrides))
95
120
 
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class TestConfigClient < Minitest::Test
5
6
  def setup
6
7
  options = Prefab::Options.new(
7
- prefab_config_override_dir: "none",
8
- prefab_config_classpath_dir: "test",
9
- prefab_envs: "unit_tests",
8
+ prefab_config_override_dir: 'none',
9
+ prefab_config_classpath_dir: 'test',
10
+ prefab_envs: 'unit_tests',
10
11
  prefab_datasources: Prefab::Options::DATASOURCES::LOCAL_ONLY
11
12
  )
12
13
 
@@ -14,59 +15,59 @@ class TestConfigClient < Minitest::Test
14
15
  end
15
16
 
16
17
  def test_load
17
- assert_equal "test sample value", @config_client.get("sample")
18
- assert_equal 123, @config_client.get("sample_int")
19
- assert_equal 12.12, @config_client.get("sample_double")
20
- assert_equal true, @config_client.get("sample_bool")
21
- assert_equal :ERROR, @config_client.get("log-level.app")
18
+ assert_equal 'test sample value', @config_client.get('sample')
19
+ assert_equal 123, @config_client.get('sample_int')
20
+ assert_equal 12.12, @config_client.get('sample_double')
21
+ assert_equal true, @config_client.get('sample_bool')
22
+ assert_equal :ERROR, @config_client.get('log-level.app')
22
23
  end
23
24
 
24
25
  def test_initialization_timeout_error
25
26
  options = Prefab::Options.new(
26
- api_key: "123-ENV-KEY-SDK",
27
+ api_key: '123-ENV-KEY-SDK',
27
28
  initialization_timeout_sec: 0.01,
28
29
  logdev: StringIO.new
29
30
  )
30
31
 
31
32
  err = assert_raises(Prefab::Errors::InitializationTimeoutError) do
32
- Prefab::Client.new(options).config_client.get("anything")
33
+ Prefab::Client.new(options).config_client.get('anything')
33
34
  end
34
35
 
35
36
  assert_match(/couldn't initialize in 0.01 second timeout/, err.message)
36
37
  end
37
38
 
38
39
  def test_prefab_envs_is_forgiving
39
- assert_equal ["my_env"], Prefab::Options.new(
40
- prefab_envs: "my_env",
40
+ assert_equal ['my_env'], Prefab::Options.new(
41
+ prefab_envs: 'my_env'
41
42
  ).prefab_envs
42
43
 
43
- assert_equal ["my_env", "a_second_env"], Prefab::Options.new(
44
- prefab_envs: ["my_env", "a_second_env"],
44
+ assert_equal %w[my_env a_second_env], Prefab::Options.new(
45
+ prefab_envs: %w[my_env a_second_env]
45
46
  ).prefab_envs
46
47
  end
47
48
 
48
49
  def test_prefab_envs_env_var
49
- ENV["PREFAB_ENVS"] = "one,two"
50
- assert_equal ["one", "two"], Prefab::Options.new().prefab_envs
50
+ ENV['PREFAB_ENVS'] = 'one,two'
51
+ assert_equal %w[one two], Prefab::Options.new.prefab_envs
51
52
  end
52
53
 
53
54
  def test_invalid_api_key_error
54
55
  options = Prefab::Options.new(
55
- api_key: "",
56
+ api_key: ''
56
57
  )
57
58
 
58
59
  err = assert_raises(Prefab::Errors::InvalidApiKeyError) do
59
- Prefab::Client.new(options).config_client.get("anything")
60
+ Prefab::Client.new(options).config_client.get('anything')
60
61
  end
61
62
 
62
63
  assert_match(/No API key/, err.message)
63
64
 
64
65
  options = Prefab::Options.new(
65
- api_key: "invalid",
66
+ api_key: 'invalid'
66
67
  )
67
68
 
68
69
  err = assert_raises(Prefab::Errors::InvalidApiKeyError) do
69
- Prefab::Client.new(options).config_client.get("anything")
70
+ Prefab::Client.new(options).config_client.get('anything')
70
71
  end
71
72
 
72
73
  assert_match(/format is invalid/, err.message)
@@ -1,83 +1,90 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'test_helper'
3
4
 
4
5
  class TestConfigLoader < Minitest::Test
5
6
  def setup
6
7
  options = Prefab::Options.new(
7
- prefab_config_override_dir: "none",
8
- prefab_config_classpath_dir: "test",
9
- prefab_envs: "unit_tests"
8
+ prefab_config_override_dir: 'none',
9
+ prefab_config_classpath_dir: 'test',
10
+ prefab_envs: 'unit_tests'
10
11
  )
11
12
  @loader = Prefab::ConfigLoader.new(MockBaseClient.new(options))
12
13
  end
13
14
 
14
15
  def test_load
15
- should_be :int, 123, "sample_int"
16
- should_be :string, "test sample value", "sample"
17
- should_be :bool, true, "sample_bool"
18
- should_be :double, 12.12, "sample_double"
16
+ should_be :int, 123, 'sample_int'
17
+ should_be :string, 'test sample value', 'sample'
18
+ should_be :bool, true, 'sample_bool'
19
+ should_be :double, 12.12, 'sample_double'
19
20
  end
20
21
 
21
22
  def test_nested
22
- should_be :string, "nested value", "nested.values.string"
23
- should_be :string, "top level", "nested.values"
24
- should_be :log_level, :ERROR, "log-level.app"
25
- should_be :log_level, :WARN, "log-level.app.controller.hello"
26
- should_be :log_level, :INFO, "log-level.app.controller.hello.index"
23
+ should_be :string, 'nested value', 'nested.values.string'
24
+ should_be :string, 'top level', 'nested.values'
25
+ should_be :log_level, :ERROR, 'log-level.app'
26
+ should_be :log_level, :WARN, 'log-level.app.controller.hello'
27
+ should_be :log_level, :INFO, 'log-level.app.controller.hello.index'
27
28
  end
28
29
 
29
30
  def test_invalid_log_level
30
- should_be :log_level, :NOT_SET_LOG_LEVEL, "log-level.invalid"
31
+ should_be :log_level, :NOT_SET_LOG_LEVEL, 'log-level.invalid'
31
32
  end
32
33
 
33
34
  def test_load_without_unit_test_env
34
35
  options = Prefab::Options.new(
35
- prefab_config_override_dir: "none",
36
- prefab_config_classpath_dir: "test",
36
+ prefab_config_override_dir: 'none',
37
+ prefab_config_classpath_dir: 'test'
37
38
  # no prefab_envs
38
39
  )
39
40
  @loader = Prefab::ConfigLoader.new(MockBaseClient.new(options))
40
- should_be :string, "default sample value", "sample"
41
- should_be :bool, true, "sample_bool"
41
+ should_be :string, 'default sample value', 'sample'
42
+ should_be :bool, true, 'sample_bool'
42
43
  end
43
44
 
44
45
  def test_highwater
45
46
  assert_equal 0, @loader.highwater_mark
46
- @loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
47
+ @loader.set(Prefab::Config.new(id: 1, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 456))]),
48
+ 'test')
47
49
  assert_equal 1, @loader.highwater_mark
48
50
 
49
- @loader.set(Prefab::Config.new(id: 5, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
51
+ @loader.set(Prefab::Config.new(id: 5, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 456))]),
52
+ 'test')
50
53
  assert_equal 5, @loader.highwater_mark
51
- @loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]),"test")
54
+ @loader.set(Prefab::Config.new(id: 2, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 456))]),
55
+ 'test')
52
56
  assert_equal 5, @loader.highwater_mark
53
57
  end
54
58
 
55
59
  def test_keeps_most_recent
56
60
  assert_equal 0, @loader.highwater_mark
57
- @loader.set(Prefab::Config.new(id: 1, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 1))]),"test")
61
+ @loader.set(Prefab::Config.new(id: 1, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 1))]),
62
+ 'test')
58
63
  assert_equal 1, @loader.highwater_mark
59
- should_be :int, 1, "sample_int"
64
+ should_be :int, 1, 'sample_int'
60
65
 
61
- @loader.set(Prefab::Config.new(id: 4, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 4))]),"test")
66
+ @loader.set(Prefab::Config.new(id: 4, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 4))]),
67
+ 'test')
62
68
  assert_equal 4, @loader.highwater_mark
63
- should_be :int, 4, "sample_int"
69
+ should_be :int, 4, 'sample_int'
64
70
 
65
- @loader.set(Prefab::Config.new(id: 2, key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 2))]),"test")
71
+ @loader.set(Prefab::Config.new(id: 2, key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 2))]),
72
+ 'test')
66
73
  assert_equal 4, @loader.highwater_mark
67
- should_be :int, 4, "sample_int"
74
+ should_be :int, 4, 'sample_int'
68
75
  end
69
76
 
70
77
  def test_api_precedence
71
- should_be :int, 123, "sample_int"
78
+ should_be :int, 123, 'sample_int'
72
79
 
73
- @loader.set(Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: Prefab::ConfigValue.new(int: 456))]), "test")
74
- should_be :int, 456, "sample_int"
80
+ @loader.set(Prefab::Config.new(key: 'sample_int', rows: [config_row(Prefab::ConfigValue.new(int: 456))]), 'test')
81
+ should_be :int, 456, 'sample_int'
75
82
  end
76
83
 
77
84
  def test_api_deltas
78
85
  val = Prefab::ConfigValue.new(int: 456)
79
- config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)])
80
- @loader.set(config, "test")
86
+ config = Prefab::Config.new(key: 'sample_int', rows: [config_row(val)])
87
+ @loader.set(config, 'test')
81
88
 
82
89
  configs = Prefab::Configs.new
83
90
  configs.configs << config
@@ -86,11 +93,11 @@ class TestConfigLoader < Minitest::Test
86
93
 
87
94
  def test_loading_tombstones_removes_entries
88
95
  val = Prefab::ConfigValue.new(int: 456)
89
- config = Prefab::Config.new(key: "sample_int", rows: [Prefab::ConfigRow.new(value: val)], id: 2)
90
- @loader.set(config, "test")
96
+ config = Prefab::Config.new(key: 'sample_int', rows: [config_row(val)], id: 2)
97
+ @loader.set(config, 'test')
91
98
 
92
- config = Prefab::Config.new(key: "sample_int", rows: [], id: 3)
93
- @loader.set(config, "test")
99
+ config = Prefab::Config.new(key: 'sample_int', rows: [], id: 3)
100
+ @loader.set(config, 'test')
94
101
 
95
102
  configs = Prefab::Configs.new
96
103
  assert_equal configs, @loader.get_api_deltas
@@ -99,7 +106,11 @@ class TestConfigLoader < Minitest::Test
99
106
  private
100
107
 
101
108
  def should_be(type, value, key)
102
- assert_equal type, @loader.calc_config[key][:config].rows[0].value.type
103
- assert_equal value, @loader.calc_config[key][:config].rows[0].value.send(type)
109
+ assert_equal type, @loader.calc_config[key][:config].rows[0].values[0].value.type
110
+ assert_equal value, @loader.calc_config[key][:config].rows[0].values[0].value.send(type)
111
+ end
112
+
113
+ def config_row(value)
114
+ Prefab::ConfigRow.new(values: [Prefab::ConditionalValue.new(value: value)])
104
115
  end
105
116
  end