Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ lib/tes*

#For rubymine
*.iml
.idea/**
.idea/**

# Claude Code settings
.claude/
21 changes: 2 additions & 19 deletions lib/reforge/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,13 @@ def get_api_deltas

def load_classpath_config
return {} if @prefab_options.datafile?
classpath_dir = @prefab_options.prefab_config_classpath_dir
rtn = load_glob(File.join(classpath_dir, '.prefab.default.config.yaml'))
@prefab_options.prefab_envs.each do |env|
rtn = rtn.merge load_glob(File.join(classpath_dir, ".prefab.#{env}.config.yaml"))
end
rtn
{}
end

def load_local_overrides
return {} if @prefab_options.datafile?
override_dir = @prefab_options.prefab_config_override_dir
rtn = load_glob(File.join(override_dir, '.prefab.default.config.yaml'))
@prefab_options.prefab_envs.each do |env|
rtn = rtn.merge load_glob(File.join(override_dir, ".prefab.#{env}.config.yaml"))
end
rtn
{}
end

def load_glob(glob)
rtn = {}
Dir.glob(glob).each do |file|
Reforge::YAMLConfigParser.new(file, @base_client).merge(rtn)
end
rtn
end
end
end
9 changes: 0 additions & 9 deletions lib/reforge/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class Options
attr_reader :on_no_default
attr_reader :initialization_timeout_sec
attr_reader :on_init_failure
attr_reader :prefab_config_override_dir
attr_reader :prefab_config_classpath_dir
attr_reader :prefab_envs
attr_reader :collect_sync_interval
attr_reader :use_local_cache
attr_reader :datafile
Expand Down Expand Up @@ -56,9 +53,6 @@ module DATASOURCES
initialization_timeout_sec: 10, # how long to wait before on_init_failure
on_init_failure: ON_INITIALIZATION_FAILURE::RAISE,
prefab_datasources: (ENV['REFORGE_DATASOURCES'] || ENV['PREFAB_DATASOURCES']) == 'LOCAL_ONLY' ? DATASOURCES::LOCAL_ONLY : DATASOURCES::ALL,
prefab_config_override_dir: Dir.home,
prefab_config_classpath_dir: '.', # where to load local overrides
prefab_envs: ENV['PREFAB_ENVS'].nil? ? [] : ENV['PREFAB_ENVS'].split(','),
collect_logger_counts: true,
collect_max_paths: DEFAULT_MAX_PATHS,
collect_sync_interval: nil,
Expand Down Expand Up @@ -86,9 +80,6 @@ module DATASOURCES
warn '[DEPRECATION] x_datafile is deprecated. Please provide `datafile` instead'
end

@prefab_config_classpath_dir = prefab_config_classpath_dir
@prefab_config_override_dir = prefab_config_override_dir
@prefab_envs = Array(prefab_envs)
@collect_logger_counts = collect_logger_counts
@collect_max_paths = collect_max_paths
@collect_sync_interval = collect_sync_interval
Expand Down
2 changes: 0 additions & 2 deletions test/.prefab.default.config.yaml

This file was deleted.

28 changes: 0 additions & 28 deletions test/.prefab.unit_tests.config.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ def base_client

def base_client_options
@_options ||= Reforge::Options.new(**{
prefab_config_override_dir: 'none',
prefab_config_classpath_dir: 'test',
prefab_envs: ['unit_tests'],
prefab_datasources: Reforge::Options::DATASOURCES::ALL,
sdk_key: ENV['REFORGE_INTEGRATION_TEST_SDK_KEY'],
sources: [
Expand Down
3 changes: 0 additions & 3 deletions test/support/common_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ def with_env(key, value, &block)
EFFECTIVELY_NEVER = 99_999 # we sync manually

DEFAULT_NEW_CLIENT_OPTIONS = {
prefab_config_override_dir: 'none',
prefab_config_classpath_dir: 'test',
prefab_envs: ['unit_tests'],
prefab_datasources: Reforge::Options::DATASOURCES::LOCAL_ONLY,
collect_sync_interval: EFFECTIVELY_NEVER,
}.freeze
Expand Down
108 changes: 0 additions & 108 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,7 @@ class TestClient < Minitest::Test
]
)

def test_get
_, err = capture_io do
client = new_client
assert_equal 'default', client.get('does.not.exist', 'default')
assert_equal 'test sample value', client.get('sample')
assert_equal 123, client.get('sample_int')
end
assert_equal '', err
end

def test_get_with_default
client = new_client
# A `false` value is not replaced with the default
assert_equal false, client.get('false_value', 'red')

# A falsy value is not replaced with the default
assert_equal 0, client.get('zero_value', 'red')

# A missing value returns the default
assert_equal 'buckets', client.get('missing_value', 'buckets')
end

def test_get_with_missing_default
client = new_client
Expand All @@ -61,83 +41,9 @@ def test_get_with_missing_default
assert_nil client.get('missing_value')
end

def test_enabled
client = new_client
assert_equal false, client.enabled?('does_not_exist')
assert_equal true, client.enabled?('enabled_flag')
assert_equal false, client.enabled?('disabled_flag')
assert_equal false, client.enabled?('flag_with_a_value')
end

def test_ff_enabled_with_user_key_match
client = new_client

ctx = { user: { key: 'jimmy' } }
assert_equal false, client.enabled?('user_key_match', ctx)
assert_equal false, Reforge::Context.with_context(ctx) { client.enabled?('user_key_match') }

ctx = { user: { key: 'abc123' } }
assert_equal true, client.enabled?('user_key_match', ctx)
assert_equal true, Reforge::Context.with_context(ctx) { client.enabled?('user_key_match') }

ctx = { user: { key: 'xyz987' } }
assert_equal true, client.enabled?('user_key_match', ctx)
assert_equal true, Reforge::Context.with_context(ctx) { client.enabled?('user_key_match') }
end

# NOTE: these are all `false` because we're doing a enabled? on a FF with string variants
# see test_ff_get_with_context for the raw value tests
def test_ff_enabled_with_context
client = new_client

ctx = { user: { domain: 'gmail.com' } }
assert_equal false, client.enabled?('just_my_domain', ctx)
assert_equal false, Reforge::Context.with_context(ctx) { client.enabled?('just_my_domain') }

ctx = { user: { domain: 'prefab.cloud' } }
assert_equal false, client.enabled?('just_my_domain', ctx)
assert_equal false, Reforge::Context.with_context(ctx) { client.enabled?('just_my_domain') }

ctx = { user: { domain: 'example.com' } }
assert_equal false, client.enabled?('just_my_domain', ctx)
assert_equal false, Reforge::Context.with_context(ctx) { client.enabled?('just_my_domain') }
end

def test_ff_get_with_context
client = new_client

ctx = { user: { domain: 'gmail.com' } }
assert_equal 'DEFAULT', client.get('just_my_domain', 'DEFAULT', ctx)
assert_equal 'DEFAULT', Reforge::Context.with_context(ctx) { client.get('just_my_domain', 'DEFAULT') }

ctx = { user: { domain: 'prefab.cloud' } }
assert_equal 'new-version', client.get('just_my_domain', 'DEFAULT', ctx)
assert_equal 'new-version', Reforge::Context.with_context(ctx) { client.get('just_my_domain', 'DEFAULT') }

ctx = { user: { domain: 'example.com' } }
assert_equal 'new-version', client.get('just_my_domain', 'DEFAULT', ctx)
assert_equal 'new-version', Reforge::Context.with_context(ctx) { client.get('just_my_domain', 'DEFAULT') }
end

def test_deprecated_no_dot_notation_ff_enabled_with_jit_context
client = new_client
# with no lookup key
assert_equal false, client.enabled?('deprecated_no_dot_notation', { domain: 'gmail.com' })
assert_equal true, client.enabled?('deprecated_no_dot_notation', { domain: 'prefab.cloud' })
assert_equal true, client.enabled?('deprecated_no_dot_notation', { domain: 'example.com' })

assert_stderr [
"[DEPRECATION] Prefab contexts should be a hash with a key of the context name and a value of a hash.",
"[DEPRECATION] Prefab contexts should be a hash with a key of the context name and a value of a hash.",
"[DEPRECATION] Prefab contexts should be a hash with a key of the context name and a value of a hash."
]
end

def test_getting_feature_flag_value
client = new_client
assert_equal false, client.enabled?('flag_with_a_value')
assert_equal 'all-features', client.get('flag_with_a_value')
end

def test_initialization_with_an_options_object
options_hash = {
Expand Down Expand Up @@ -411,21 +317,7 @@ def test_get_log_level
assert_summary client, {}
end

def test_defined
client = new_client

refute client.defined?('does_not_exist')
assert client.defined?('sample_int')
assert client.defined?('disabled_flag')
end

def test_is_ff
client = new_client

assert client.is_ff?('flag_with_a_value')
refute client.is_ff?('sample_int')
refute client.is_ff?('does_not_exist')
end

def test_with_datafile
datafile = "#{Dir.pwd}/test/fixtures/datafile.json"
Expand Down
24 changes: 0 additions & 24 deletions test/test_config_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ class TestConfigClient < Minitest::Test
def setup
super
options = Reforge::Options.new(
prefab_config_override_dir: 'none',
prefab_config_classpath_dir: 'test',
prefab_envs: 'unit_tests',
prefab_datasources: Reforge::Options::DATASOURCES::LOCAL_ONLY,
x_use_local_cache: true,
)

@config_client = Reforge::ConfigClient.new(MockBaseClient.new(options), 10)
end

def test_load
assert_equal 'test sample value', @config_client.get('sample')
assert_equal 123, @config_client.get('sample_int')
assert_equal 12.12, @config_client.get('sample_double')
assert_equal true, @config_client.get('sample_bool')
assert_equal :ERROR, @config_client.get('log-level.app')
end

def test_initialization_timeout_error
options = Reforge::Options.new(
Expand All @@ -37,20 +27,6 @@ def test_initialization_timeout_error
assert_match(/couldn't initialize in 0.01 second timeout/, err.message)
end

def test_prefab_envs_is_forgiving
assert_equal ['my_env'], Reforge::Options.new(
prefab_envs: 'my_env'
).prefab_envs

assert_equal %w[my_env a_second_env], Reforge::Options.new(
prefab_envs: %w[my_env a_second_env]
).prefab_envs
end

def test_prefab_envs_env_var
ENV['PREFAB_ENVS'] = 'one,two'
assert_equal %w[one two], Reforge::Options.new.prefab_envs
end

def test_invalid_api_key_error
options = Reforge::Options.new(
Expand Down
35 changes: 0 additions & 35 deletions test/test_config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,13 @@ class TestConfigLoader < Minitest::Test
def setup
super
options = Reforge::Options.new(
prefab_config_override_dir: 'none',
prefab_config_classpath_dir: 'test',
prefab_envs: 'unit_tests'
)
@loader = Reforge::ConfigLoader.new(MockBaseClient.new(options))
end

def test_load
should_be :int, 123, 'sample_int'
should_be :string, 'test sample value', 'sample'
should_be :bool, true, 'sample_bool'
should_be :double, 12.12, 'sample_double'
end

def test_nested
should_be :string, 'nested value', 'nested.values.string'
should_be :string, 'top level', 'nested.values'
should_be :log_level, :ERROR, 'log-level.app'
should_be :log_level, :WARN, 'log-level.app.controller.hello'
should_be :log_level, :INFO, 'log-level.app.controller.hello.index'
end

def test_invalid_log_level
should_be :log_level, :NOT_SET_LOG_LEVEL, 'log-level.invalid'
end

def test_load_without_unit_test_env
options = Reforge::Options.new(
prefab_config_override_dir: 'none',
prefab_config_classpath_dir: 'test'
# no prefab_envs
)
@loader = Reforge::ConfigLoader.new(MockBaseClient.new(options))
should_be :string, 'default sample value', 'sample'
should_be :bool, true, 'sample_bool'
end

def test_highwater
assert_equal 0, @loader.highwater_mark
Expand Down Expand Up @@ -75,12 +46,6 @@ def test_keeps_most_recent
should_be :int, 4, 'sample_int'
end

def test_api_precedence
should_be :int, 123, 'sample_int'

@loader.set(PrefabProto::Config.new(key: 'sample_int', rows: [config_row(PrefabProto::ConfigValue.new(int: 456))]), 'test')
should_be :int, 456, 'sample_int'
end

def test_api_deltas
val = PrefabProto::ConfigValue.new(int: 456)
Expand Down
Loading