Backport PR #13481 to 7.16: Fix: delegating from deprecated setting (#13484)

This commit is contained in:
Karol Bucek 2021-12-08 14:34:02 +01:00 committed by GitHub
parent d492c4ed32
commit d737554758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View file

@ -811,7 +811,7 @@ module LogStash
def validate_value def validate_value
# bypass deprecation warning # bypass deprecation warning
validate(wrapped.value) if set? wrapped.validate_value if set?
end end
end end

View file

@ -56,12 +56,15 @@ describe LogStash::Setting::SettingWithDeprecatedAlias do
end end
context "when only the deprecated alias is set" do context "when only the deprecated alias is set" do
let(:value) { "crusty_value" }
before(:each) do before(:each) do
settings.set(deprecated_setting_name, "crusty_value") settings.set(deprecated_setting_name, value)
end end
it 'resolves to the value provided for the deprecated alias' do it 'resolves to the value provided for the deprecated alias' do
expect(settings.get(canonical_setting_name)).to eq("crusty_value") expect(settings.get(canonical_setting_name)).to eq(value)
end end
it 'logs a deprecation warning' do it 'logs a deprecation warning' do
@ -69,6 +72,29 @@ describe LogStash::Setting::SettingWithDeprecatedAlias do
end end
include_examples '#validate_value success' include_examples '#validate_value success'
it 'validates deprecated alias' do
expect { settings.get_setting(canonical_setting_name).deprecated_alias.validate_value }.to_not raise_error
end
context 'using a boolean setting' do
let(:value) { true }
let(:default_value) { false }
let(:canonical_setting) { LogStash::Setting::Boolean.new(canonical_setting_name, default_value, true) }
it 'resolves to the value provided for the deprecated alias' do
expect(settings.get(canonical_setting_name)).to eq(true)
end
include_examples '#validate_value success'
it 'validates deprecated alias' do
expect { settings.get_setting(canonical_setting_name).deprecated_alias.validate_value }.to_not raise_error
end
end
end end
context "when only the canonical setting is set" do context "when only the canonical setting is set" do