qonfig 0.25.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.rubocop.yml +19 -1
- data/.travis.yml +7 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +102 -0
- data/README.md +2 -0
- data/gemfiles/with_external_deps.gemfile.lock +112 -0
- data/gemfiles/without_external_deps.gemfile.lock +102 -0
- data/lib/qonfig.rb +1 -1
- data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
- data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
- data/lib/qonfig/imports/direct_key.rb +8 -2
- data/lib/qonfig/imports/mappings.rb +8 -2
- data/lib/qonfig/loaders/basic.rb +2 -0
- data/lib/qonfig/loaders/json.rb +2 -1
- data/lib/qonfig/settings.rb +5 -1
- data/lib/qonfig/settings/key_matcher.rb +1 -1
- data/lib/qonfig/uploaders/base.rb +2 -0
- data/lib/qonfig/uploaders/yaml.rb +2 -0
- data/lib/qonfig/version.rb +1 -1
- data/qonfig.gemspec +4 -6
- data/sig/.keep +0 -0
- data/spec/features/clear_options_spec.rb +92 -0
- data/spec/features/compacted_config_spec.rb +308 -0
- data/spec/features/composition_spec.rb +207 -0
- data/spec/features/config_definition_and_representation_spec.rb +535 -0
- data/spec/features/definition_order_spec.rb +69 -0
- data/spec/features/dig_functionality_spec.rb +47 -0
- data/spec/features/dot_notation_spec.rb +159 -0
- data/spec/features/export_settings_spec.rb +138 -0
- data/spec/features/expose_json_spec.rb +281 -0
- data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
- data/spec/features/expose_self/format_option_json_spec.rb +74 -0
- data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
- data/spec/features/expose_self_spec.rb +97 -0
- data/spec/features/expose_yaml_spec.rb +263 -0
- data/spec/features/freeze_state_spec.rb +122 -0
- data/spec/features/get_config_keys_spec.rb +62 -0
- data/spec/features/get_config_values_spec.rb +41 -0
- data/spec/features/has_a_key_spec.rb +48 -0
- data/spec/features/import_settings_spec.rb +323 -0
- data/spec/features/indifferent_access_spec.rb +57 -0
- data/spec/features/inheritance_spec.rb +110 -0
- data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
- data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
- data/spec/features/load_from_env_spec.rb +240 -0
- data/spec/features/load_from_json_spec.rb +97 -0
- data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
- data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
- data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
- data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
- data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
- data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
- data/spec/features/load_from_yaml_spec.rb +110 -0
- data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
- data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
- data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
- data/spec/features/mixin_spec.rb +387 -0
- data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
- data/spec/features/plugins/pretty_print_spec.rb +86 -0
- data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
- data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
- data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
- data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
- data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
- data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
- data/spec/features/plugins_spec.rb +89 -0
- data/spec/features/reload_spec.rb +75 -0
- data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
- data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
- data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
- data/spec/features/settings_as_predicates_spec.rb +47 -0
- data/spec/features/settings_redefinition_spec.rb +30 -0
- data/spec/features/slice_functionality_spec.rb +69 -0
- data/spec/features/subset_functionality_spec.rb +49 -0
- data/spec/features/validation_spec.rb +916 -0
- data/spec/fixtures/array_settings.yml +3 -0
- data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
- data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
- data/spec/fixtures/expose_json/project.development.json +7 -0
- data/spec/fixtures/expose_json/project.json +30 -0
- data/spec/fixtures/expose_json/project.production.json +7 -0
- data/spec/fixtures/expose_json/project.staging.json +7 -0
- data/spec/fixtures/expose_json/project.test.json +7 -0
- data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
- data/spec/fixtures/expose_yaml/project.development.yml +4 -0
- data/spec/fixtures/expose_yaml/project.production.yml +4 -0
- data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
- data/spec/fixtures/expose_yaml/project.test.yml +4 -0
- data/spec/fixtures/expose_yaml/project.yml +25 -0
- data/spec/fixtures/json_array_sample.json +14 -0
- data/spec/fixtures/json_object_sample.json +9 -0
- data/spec/fixtures/json_with_empty_object.json +6 -0
- data/spec/fixtures/json_with_erb.json +6 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
- data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
- data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
- data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
- data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
- data/spec/fixtures/rubocop_settings.yml +12 -0
- data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
- data/spec/fixtures/travis_settings.yml +6 -0
- data/spec/fixtures/values_file/with_env.json +19 -0
- data/spec/fixtures/values_file/with_env.yml +17 -0
- data/spec/fixtures/values_file/without_env.json +8 -0
- data/spec/fixtures/values_file/without_env.yml +5 -0
- data/spec/fixtures/with_empty_hash.yml +4 -0
- data/spec/fixtures/with_erb_instructions.yml +3 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/meta_scopes.rb +20 -0
- data/spec/support/spec_support.rb +42 -0
- metadata +128 -11
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Non-redefineable core methods' do
|
4
|
+
specify 'fails when setting key intersects with any internal Qonfig::Settings core method' do
|
5
|
+
core_methods = (
|
6
|
+
Qonfig::Settings.instance_methods(false) |
|
7
|
+
Qonfig::Settings.private_instance_methods(false) |
|
8
|
+
%i[define_singleton_method super self]
|
9
|
+
)
|
10
|
+
|
11
|
+
expect(core_methods).not_to include(:super_test_key)
|
12
|
+
|
13
|
+
core_methods.each do |core_method|
|
14
|
+
expect do
|
15
|
+
Class.new(Qonfig::DataSet) do
|
16
|
+
setting core_method
|
17
|
+
end
|
18
|
+
end.to raise_error(Qonfig::CoreMethodIntersectionError)
|
19
|
+
|
20
|
+
expect do
|
21
|
+
Class.new(Qonfig::DataSet) do
|
22
|
+
setting :super_test_key do
|
23
|
+
setting core_method
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end.to raise_error(Qonfig::CoreMethodIntersectionError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(:pretty_print): Pretty print :)', plugin: :pretty_print do
|
4
|
+
before do
|
5
|
+
stub_const('PrettyPrintableConfig', Class.new(Qonfig::DataSet) do
|
6
|
+
setting :api do
|
7
|
+
setting :domain, 'google'
|
8
|
+
setting :creds do
|
9
|
+
setting :token, 'a0sdj10k@'
|
10
|
+
setting :login, 'D2'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :database do
|
15
|
+
setting :adapter, 'pg'
|
16
|
+
setting 'logging.queries', nil
|
17
|
+
end
|
18
|
+
|
19
|
+
setting :logging, false
|
20
|
+
setting :author, nil
|
21
|
+
end)
|
22
|
+
end
|
23
|
+
|
24
|
+
shared_examples 'pretty printing :)' do
|
25
|
+
subject(:print_to_console!) { PP.pp(config, pretty_printer_output) }
|
26
|
+
|
27
|
+
let(:pretty_printer_output) { StringIO.new }
|
28
|
+
|
29
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
30
|
+
specify 'shows config settings in beatufied format' do
|
31
|
+
print_to_console!
|
32
|
+
|
33
|
+
expect(pretty_printer_output.string).to include(
|
34
|
+
"#<#{expected_config_klass_name}:0x"
|
35
|
+
)
|
36
|
+
|
37
|
+
expect(pretty_printer_output.string).to include(
|
38
|
+
" api.domain: \"google\",\n" \
|
39
|
+
" api.creds.token: \"a0sdj10k@\",\n" \
|
40
|
+
" api.creds.login: \"D2\",\n" \
|
41
|
+
" database.adapter: \"pg\",\n" \
|
42
|
+
" database.logging.queries: nil,\n" \
|
43
|
+
" logging: false,\n" \
|
44
|
+
" author: nil>\n"
|
45
|
+
)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
specify 'shows config settings in beatufied format' do
|
49
|
+
print_to_console!
|
50
|
+
value_space = SpecSupport.from_object_id_space_to_value_space(config)
|
51
|
+
|
52
|
+
expect(pretty_printer_output.string).to eq(
|
53
|
+
"#<#{expected_config_klass_name}:0x#{value_space}\n" \
|
54
|
+
" api.domain: \"google\",\n" \
|
55
|
+
" api.creds.token: \"a0sdj10k@\",\n" \
|
56
|
+
" api.creds.login: \"D2\",\n" \
|
57
|
+
" database.adapter: \"pg\",\n" \
|
58
|
+
" database.logging.queries: nil,\n" \
|
59
|
+
" logging: false,\n" \
|
60
|
+
" author: nil>\n"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'pretty-printed Qonfig::DataSet' do
|
67
|
+
include_examples 'pretty printing :)' do
|
68
|
+
let(:config) { PrettyPrintableConfig.new }
|
69
|
+
let(:expected_config_klass_name) { 'PrettyPrintableConfig' }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'pretty-printed Qonfig::Settings' do
|
74
|
+
include_examples 'pretty printing :)' do
|
75
|
+
let(:config) { PrettyPrintableConfig.new.settings }
|
76
|
+
let(:expected_config_klass_name) { 'Qonfig::Settings' }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'pretty-printed Qonfig::Compacted' do
|
81
|
+
include_examples 'pretty printing :)' do
|
82
|
+
let(:config) { PrettyPrintableConfig.new.compacted }
|
83
|
+
let(:expected_config_klass_name) { 'Qonfig::Compacted' }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): #expose_self => format: :toml', plugin: :toml do
|
4
|
+
specify ':toml-format support' do
|
5
|
+
class ExposeTomlEndDataConfig < Qonfig::DataSet
|
6
|
+
setting :staging_env do
|
7
|
+
expose_self format: :toml, env: :staging
|
8
|
+
end
|
9
|
+
|
10
|
+
setting :prod_env do
|
11
|
+
expose_self format: :toml, env: :production
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :test_env do
|
15
|
+
expose_self format: :toml, env: :test
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
config = ExposeTomlEndDataConfig.new
|
20
|
+
|
21
|
+
# NOTE: production env
|
22
|
+
expect(config.settings.prod_env.credentials.user).to eq('admin')
|
23
|
+
expect(config.settings.prod_env.credentials.password).to eq('123')
|
24
|
+
expect(config.settings.prod_env.credentials.enabled).to eq(true)
|
25
|
+
expect(config.settings.prod_env.api).to eq('google.com')
|
26
|
+
expect(config.settings.prod_env.ports).to eq([10001, 10002, 10003])
|
27
|
+
|
28
|
+
# NOTE: test env
|
29
|
+
expect(config.settings.test_env.credentials.user).to eq('megaman')
|
30
|
+
expect(config.settings.test_env.credentials.password).to eq('atata123')
|
31
|
+
expect(config.settings.test_env.credentials.enabled).to eq(false)
|
32
|
+
expect(config.settings.test_env.api).to eq('yandex.ru')
|
33
|
+
expect(config.settings.test_env.ports).to eq([1, 2, 3])
|
34
|
+
|
35
|
+
# NOTE: staging env
|
36
|
+
expect(config.settings.staging_env.credentials.user).to eq('diablo')
|
37
|
+
expect(config.settings.staging_env.credentials.password).to eq('testornot')
|
38
|
+
expect(config.settings.staging_env.credentials.enabled).to eq(true)
|
39
|
+
expect(config.settings.staging_env.api).to eq('battle.net')
|
40
|
+
expect(config.settings.staging_env.ports).to eq([111, 222, 333])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
__END__
|
45
|
+
|
46
|
+
[production]
|
47
|
+
api = "google.com"
|
48
|
+
ports = [ 10001, 10002, 10003 ]
|
49
|
+
|
50
|
+
[production.credentials]
|
51
|
+
user = "admin"
|
52
|
+
password = "123"
|
53
|
+
enabled = true
|
54
|
+
|
55
|
+
[test]
|
56
|
+
api = "yandex.ru"
|
57
|
+
ports = [ 1, 2, 3 ]
|
58
|
+
|
59
|
+
[test.credentials]
|
60
|
+
user = "megaman"
|
61
|
+
password = "atata123"
|
62
|
+
enabled = false
|
63
|
+
|
64
|
+
[staging]
|
65
|
+
api = "battle.net"
|
66
|
+
ports = [ 111, 222, 333 ]
|
67
|
+
|
68
|
+
[staging.credentials]
|
69
|
+
user = "diablo"
|
70
|
+
password = "testornot"
|
71
|
+
enabled = true
|
@@ -0,0 +1,221 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): expose TOML file', plugin: :toml do
|
4
|
+
specify 'defines config object by toml instructions and specific environment settings' do
|
5
|
+
class ExposeTOMLConfig < Qonfig::DataSet
|
6
|
+
toml_file_path = SpecSupport.fixture_path('plugins', 'toml', 'expose_toml', 'project.toml')
|
7
|
+
|
8
|
+
setting :file_name_based do
|
9
|
+
setting :test_env do
|
10
|
+
# spec/fixtures/plugins/toml/expose_toml/project.test.toml
|
11
|
+
expose_toml toml_file_path, via: :file_name, env: :test
|
12
|
+
end
|
13
|
+
|
14
|
+
setting :prod_env do
|
15
|
+
# spec/fixtures/plugins/toml/expose_toml/project.production.toml
|
16
|
+
expose_toml toml_file_path, via: :file_name, env: :production
|
17
|
+
end
|
18
|
+
|
19
|
+
setting :stage_env do
|
20
|
+
# spec/fixtures/plugins/toml/expose_toml/project.staging.toml
|
21
|
+
expose_toml toml_file_path, via: :file_name, env: :staging
|
22
|
+
end
|
23
|
+
|
24
|
+
setting :dev_env do
|
25
|
+
# spec/fixtures/plugins/toml/expose_toml/project.development.yml
|
26
|
+
expose_toml toml_file_path, via: :file_name, env: :development
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
setting :env_based do
|
31
|
+
setting :test_env do
|
32
|
+
# spec/fixtures/plugins/toml/expose_toml/project.toml
|
33
|
+
expose_toml toml_file_path, via: :env_key, env: :test
|
34
|
+
end
|
35
|
+
|
36
|
+
setting :prod_env do
|
37
|
+
# spec/fixtures/plugins/toml/expose_toml/project.toml
|
38
|
+
expose_toml toml_file_path, via: :env_key, env: :production
|
39
|
+
end
|
40
|
+
|
41
|
+
setting :stage_env do
|
42
|
+
# spec/fixtures/plugins/toml/expose_toml/project.toml
|
43
|
+
expose_toml toml_file_path, via: :env_key, env: :staging
|
44
|
+
end
|
45
|
+
|
46
|
+
setting :dev_env do
|
47
|
+
# spec/fixtures/plugins/toml/expose_toml/project.toml
|
48
|
+
expose_toml toml_file_path, via: :env_key, env: :development
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
settings = ExposeTOMLConfig.new.settings
|
54
|
+
|
55
|
+
# NOTE: file-name based expose
|
56
|
+
# spec/fixtures/plugins/toml/expose_toml/project.test.toml
|
57
|
+
expect(settings.file_name_based.test_env.api_mode_enabled).to eq(false)
|
58
|
+
expect(settings.file_name_based.test_env.db_driver).to eq('in_memory')
|
59
|
+
expect(settings.file_name_based.test_env.logging).to eq(false)
|
60
|
+
expect(settings.file_name_based.test_env.credentials).to eq({})
|
61
|
+
# spec/fixtures/plugins/toml/expose_toml/project.production.toml
|
62
|
+
expect(settings.file_name_based.prod_env.api_mode_enabled).to eq(true)
|
63
|
+
expect(settings.file_name_based.prod_env.db_driver).to eq('rom')
|
64
|
+
expect(settings.file_name_based.prod_env.logging).to eq(true)
|
65
|
+
expect(settings.file_name_based.prod_env.credentials).to eq({})
|
66
|
+
# spec/fixtures/plugins/toml/expose_toml/project.development.toml
|
67
|
+
expect(settings.file_name_based.dev_env.api_mode_enabled).to eq(true)
|
68
|
+
expect(settings.file_name_based.dev_env.db_driver).to eq('sequel')
|
69
|
+
expect(settings.file_name_based.dev_env.logging).to eq(false)
|
70
|
+
expect(settings.file_name_based.dev_env.credentials).to eq({})
|
71
|
+
# spec/fixtures/plugins/toml/expose_toml/project.staging.toml
|
72
|
+
expect(settings.file_name_based.stage_env.api_mode_enabled).to eq(true)
|
73
|
+
expect(settings.file_name_based.stage_env.db_driver).to eq('active_record')
|
74
|
+
expect(settings.file_name_based.stage_env.logging).to eq(true)
|
75
|
+
expect(settings.file_name_based.stage_env.credentials).to eq({})
|
76
|
+
|
77
|
+
# NOTE: environment based expose
|
78
|
+
# spec/fixtures/plugins/toml/expose_toml/projecttoml (table: 'test')
|
79
|
+
expect(settings.env_based.test_env.api_mode_enabled).to eq(true)
|
80
|
+
expect(settings.env_based.test_env.db_driver).to eq('in_memory')
|
81
|
+
expect(settings.env_based.test_env.logging).to eq(false)
|
82
|
+
expect(settings.env_based.test_env.throttle_requests).to eq(false)
|
83
|
+
expect(settings.env_based.test_env.credentials).to eq({})
|
84
|
+
# spec/fixtures/plugins/toml/expose_toml/project.toml (table: 'production')
|
85
|
+
expect(settings.env_based.prod_env.api_mode_enabled).to eq(true)
|
86
|
+
expect(settings.env_based.prod_env.db_driver).to eq('rom')
|
87
|
+
expect(settings.env_based.prod_env.logging).to eq(true)
|
88
|
+
expect(settings.env_based.prod_env.throttle_requests).to eq(true)
|
89
|
+
expect(settings.env_based.prod_env.credentials).to eq({})
|
90
|
+
# spec/fixtures/plugins/toml/expose_toml/projecttoml (table: 'development')
|
91
|
+
expect(settings.env_based.dev_env.api_mode_enabled).to eq(true)
|
92
|
+
expect(settings.env_based.dev_env.db_driver).to eq('sequel')
|
93
|
+
expect(settings.env_based.dev_env.logging).to eq(false)
|
94
|
+
expect(settings.env_based.dev_env.throttle_requests).to eq(false)
|
95
|
+
expect(settings.env_based.dev_env.credentials).to eq({})
|
96
|
+
# spec/fixtures/plugins/toml/expose_toml/projecttoml (table: 'staging')
|
97
|
+
expect(settings.env_based.stage_env.api_mode_enabled).to eq(true)
|
98
|
+
expect(settings.env_based.stage_env.db_driver).to eq('active_record')
|
99
|
+
expect(settings.env_based.stage_env.logging).to eq(true)
|
100
|
+
expect(settings.env_based.stage_env.throttle_requests).to eq(true)
|
101
|
+
expect(settings.env_based.stage_env.credentials).to eq({})
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'failures and inconsistent situations' do
|
105
|
+
describe 'definition level errors' do
|
106
|
+
specify 'fails when :env attribute has non-string / non-symbol / non-numeric value' do
|
107
|
+
expect do
|
108
|
+
Class.new(Qonfig::DataSet) do
|
109
|
+
expose_toml SpecSupport.fixture_path(
|
110
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
111
|
+
), via: :env_key, env: Object.new
|
112
|
+
end
|
113
|
+
end.to raise_error(Qonfig::ArgumentError)
|
114
|
+
end
|
115
|
+
|
116
|
+
specify 'fails when :env is empty' do
|
117
|
+
expect do
|
118
|
+
Class.new(Qonfig::DataSet) do
|
119
|
+
expose_toml SpecSupport.fixture_path(
|
120
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
121
|
+
), via: :env_key, env: ''
|
122
|
+
end
|
123
|
+
end.to raise_error(Qonfig::ArgumentError)
|
124
|
+
end
|
125
|
+
|
126
|
+
specify 'fails when provided :via is not supported' do
|
127
|
+
expect do
|
128
|
+
Class.new(Qonfig::DataSet) do
|
129
|
+
expose_toml SpecSupport.fixture_path(
|
130
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
131
|
+
), via: :auto, env: :production
|
132
|
+
end
|
133
|
+
end.to raise_error(Qonfig::ArgumentError)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'initialization level errors' do
|
138
|
+
describe 'strict mode' do
|
139
|
+
specify(
|
140
|
+
'disabled (non-strict): ' \
|
141
|
+
'file existence requirement + yaml-env-key existence requirement'
|
142
|
+
) do
|
143
|
+
# NOTE: file does not exist + env key does not exist in toml file
|
144
|
+
class NoFileNonStrictExposeTOMLConfig < Qonfig::DataSet
|
145
|
+
setting :non_strict_by_file do
|
146
|
+
expose_toml SpecSupport.fixture_path(
|
147
|
+
'plugins', 'toml', 'expose_toml', 'nonexistent.toml'
|
148
|
+
), strict: false, via: :file_name, env: :development
|
149
|
+
end
|
150
|
+
|
151
|
+
setting :non_strict_by_env do
|
152
|
+
expose_toml SpecSupport.fixture_path(
|
153
|
+
'plugins', 'toml', 'expose_toml', 'nonexistent.toml'
|
154
|
+
), strict: false, via: :env_key, env: :development
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
expect(NoFileNonStrictExposeTOMLConfig.new.to_h).to match(
|
159
|
+
'non_strict_by_file' => {},
|
160
|
+
'non_strict_by_env' => {}
|
161
|
+
)
|
162
|
+
|
163
|
+
# NOTE: file is exist + env key does not exist in toml file
|
164
|
+
class NoEnvKeyNonStrictExposeTOMLConfig < Qonfig::DataSet
|
165
|
+
setting :non_strict_by_file do
|
166
|
+
expose_toml SpecSupport.fixture_path(
|
167
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
168
|
+
), strict: false, via: :file_name, env: :nonexistent
|
169
|
+
end
|
170
|
+
|
171
|
+
setting :non_strict_by_env do
|
172
|
+
expose_toml SpecSupport.fixture_path(
|
173
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
174
|
+
), strict: false, via: :env_key, env: :nonexistent
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
expect(NoEnvKeyNonStrictExposeTOMLConfig.new.to_h).to match(
|
179
|
+
'non_strict_by_file' => {},
|
180
|
+
'non_strict_by_env' => {}
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
184
|
+
specify(
|
185
|
+
'enabled (strict, by default): ' \
|
186
|
+
'file existence requirement + yaml-env-key existence requirement'
|
187
|
+
) do
|
188
|
+
# NOTE: file does not exist
|
189
|
+
class StrictFileViaFileNameConfig < Qonfig::DataSet
|
190
|
+
expose_toml SpecSupport.fixture_path(
|
191
|
+
'plugins', 'toml', 'expose_toml', 'nonexistent.toml'
|
192
|
+
), via: :file_name, env: :production
|
193
|
+
end
|
194
|
+
|
195
|
+
# NOTE: file does not exist
|
196
|
+
class StrictFileViaEnvKeyConfig < Qonfig::DataSet
|
197
|
+
expose_toml SpecSupport.fixture_path(
|
198
|
+
'plugins', 'toml', 'expose_toml', 'nonexistent.toml'
|
199
|
+
), via: :env_key, env: :production
|
200
|
+
end
|
201
|
+
|
202
|
+
# NOTE: file does not exist
|
203
|
+
expect { StrictFileViaFileNameConfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
204
|
+
expect { StrictFileViaEnvKeyConfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
205
|
+
|
206
|
+
# NOTE:
|
207
|
+
# - file exists but env key does not exist
|
208
|
+
# - file: spec/fixtures/plugins/toml/expose_toml/project.toml
|
209
|
+
class NonExistentEnvKeyConfig < Qonfig::DataSet
|
210
|
+
expose_toml SpecSupport.fixture_path(
|
211
|
+
'plugins', 'toml', 'expose_toml', 'project.toml'
|
212
|
+
), via: :env_key, env: :nonexistent
|
213
|
+
end
|
214
|
+
|
215
|
+
# NOTE: env key does not exist
|
216
|
+
expect { NonExistentEnvKeyConfig.new }.to raise_error(Qonfig::ExposeError)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): #load_from_self => format: :toml', plugin: :toml do
|
4
|
+
specify ':toml-format support' do
|
5
|
+
class TomlEndDataConfig < Qonfig::DataSet
|
6
|
+
load_from_self format: :toml
|
7
|
+
end
|
8
|
+
|
9
|
+
config = TomlEndDataConfig.new
|
10
|
+
|
11
|
+
expect(config.settings.amount).to eq(123.456)
|
12
|
+
expect(config.settings.methods).to eq([['test'], [true, false], [1, 2, 3]])
|
13
|
+
expect(config.settings.credentials.user).to eq('admin')
|
14
|
+
expect(config.settings.credentials.password).to eq('123')
|
15
|
+
expect(config.settings.credentials.enabled).to eq(true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
__END__
|
20
|
+
|
21
|
+
amount = 123.456
|
22
|
+
methods = [ [ "test" ], [ true, false ], [ 1, 2, 3 ] ]
|
23
|
+
|
24
|
+
[credentials]
|
25
|
+
user = "admin"
|
26
|
+
password = "123"
|
27
|
+
enabled = true
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Plugins(toml): Load from .toml (TOML)', plugin: :toml do
|
4
|
+
specify 'defines config object by toml instructions' do
|
5
|
+
class TomlConfig < Qonfig::DataSet
|
6
|
+
load_from_toml SpecSupport.fixture_path('plugins', 'toml', 'toml_sample_with_all_types.toml')
|
7
|
+
end
|
8
|
+
|
9
|
+
TomlConfig.new.settings.tap do |conf|
|
10
|
+
expect(conf.key_in_air).to eq('TOML Example')
|
11
|
+
|
12
|
+
expect(conf.inline_table_of_tables).to eq([
|
13
|
+
{ 'x' => 1, 'y' => 2, 'z' => 3 },
|
14
|
+
{ 'x' => 7, 'y' => 8, 'z' => 9 },
|
15
|
+
{ 'x' => 2, 'y' => 4, 'z' => 8 }
|
16
|
+
])
|
17
|
+
|
18
|
+
expect(conf.strings.simple_string).to eq('Simple String')
|
19
|
+
expect(conf.strings.first_multi_line_string).to eq("first multiline\nstring defined")
|
20
|
+
expect(conf.strings.second_multiline_string).to eq("second multiline\nstring defined\n")
|
21
|
+
|
22
|
+
expect(conf.times.first_format).to eq(Time.utc(1979, 0o5, 27, 0o7, 32, 0))
|
23
|
+
expect(conf.times.second_format).to eq(Time.new(1979, 0o5, 27, 0o0, 32, 0, '-07:00'))
|
24
|
+
expect(conf.times.third_format).to eq(Time.new(1979, 0o5, 27, 0o0, 32, 0.999999, '-07:00'))
|
25
|
+
|
26
|
+
expect(conf.arrays.array_of_integers).to eq([1, 2, 3])
|
27
|
+
expect(conf.arrays.array_of_strings).to eq(%w[a b c])
|
28
|
+
expect(conf.arrays.array_of_integer_arrays).to eq([[1, 2], [3, 4, 5]])
|
29
|
+
expect(conf.arrays.array_of_different_string_literals).to eq(%w[azaza trazaza kek pek])
|
30
|
+
expect(conf.arrays.array_of_multityped_arrays).to eq([[1, 2], %w[a b c]])
|
31
|
+
expect(conf.arrays.multyline_array).to eq(%w[super puper])
|
32
|
+
|
33
|
+
expect(conf.number_definitions.number_with_parts).to eq([8_001, 8_001, 8_002])
|
34
|
+
expect(conf.number_definitions.number_with_idiot_parts).to eq(5_000)
|
35
|
+
expect(conf.number_definitions.simple_float).to eq(3.12138)
|
36
|
+
expect(conf.number_definitions.epic_float).to eq(5e+22)
|
37
|
+
expect(conf.number_definitions.haha_float).to eq(1e6)
|
38
|
+
expect(conf.number_definitions.wow_float).to eq(-2E-2)
|
39
|
+
|
40
|
+
expect(conf.booleans.boolean_true).to eq(true)
|
41
|
+
expect(conf.booleans.boolean_false).to eq(false)
|
42
|
+
|
43
|
+
expect(conf.nesteds.first.ip).to eq('10.0.0.1')
|
44
|
+
expect(conf.nesteds.first.host).to eq('google.sru')
|
45
|
+
expect(conf.nesteds.second.ip).to eq('10.0.0.2')
|
46
|
+
expect(conf.nesteds.second.host).to eq('poogle.fru')
|
47
|
+
|
48
|
+
expect(conf.deep_nesteds).to eq([
|
49
|
+
{
|
50
|
+
'name' => 'apple',
|
51
|
+
'first' => { 'model' => 'iphone xs', 'color' => 'white' },
|
52
|
+
'second' => [{ 'model' => 'iphone x' }],
|
53
|
+
'third' => [{ 'model' => 'iphone se' }]
|
54
|
+
},
|
55
|
+
{
|
56
|
+
'name'=>'xiaomi',
|
57
|
+
'fourth'=>[{ 'model' => 'mi8 explorer edition' }]
|
58
|
+
}
|
59
|
+
])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
specify 'support for Pathanme in filepath' do
|
64
|
+
class PathanmeTomlLoadCheckConfig < Qonfig::DataSet
|
65
|
+
load_from_toml Pathname.new(SpecSupport.fixture_path('plugins', 'toml', 'mini_file.toml'))
|
66
|
+
end
|
67
|
+
|
68
|
+
config = PathanmeTomlLoadCheckConfig.new
|
69
|
+
|
70
|
+
expect(config.settings.enabled).to eq(false)
|
71
|
+
expect(config.settings.adapter).to eq('sidekiq')
|
72
|
+
expect(config.settings.credentials.user).to eq('0exp')
|
73
|
+
expect(config.settings.credentials.timeout).to eq(123)
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ':strict mode option (when file does not exist)' do
|
77
|
+
context 'when :strict => true (by default)' do
|
78
|
+
specify 'fails with corresponding error' do
|
79
|
+
# check default behaviour (strict: true)
|
80
|
+
class FailingTomlConfig < Qonfig::DataSet
|
81
|
+
load_from_toml 'no_file.toml'
|
82
|
+
end
|
83
|
+
|
84
|
+
expect { FailingTomlConfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
85
|
+
|
86
|
+
class ExplicitlyStrictedTomlConfig < Qonfig::DataSet
|
87
|
+
load_from_toml 'no_file.toml', strict: true
|
88
|
+
end
|
89
|
+
|
90
|
+
expect { ExplicitlyStrictedTomlConfig.new }.to raise_error(Qonfig::FileNotFoundError)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'when :strict => false' do
|
95
|
+
specify 'does not fail - empty config' do
|
96
|
+
class NonFailingTomlConfig < Qonfig::DataSet
|
97
|
+
load_from_toml 'no_file.toml', strict: false
|
98
|
+
|
99
|
+
setting :nested do
|
100
|
+
load_from_toml 'no_file.toml', strict: false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
expect { NonFailingTomlConfig.new }.not_to raise_error
|
105
|
+
expect(NonFailingTomlConfig.new.to_h).to eq('nested' => {})
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|