|
25 | 25 | let(:default_value) { "DeFaUlT" } |
26 | 26 |
|
27 | 27 | let(:settings) { LogStash::Settings.new } |
28 | | - let(:canonical_setting) { LogStash::Setting::String.new(canonical_setting_name, default_value, true) } |
| 28 | + let(:canonical_setting) { LogStash::Setting::StringSetting.new(canonical_setting_name, default_value, true) } |
| 29 | + |
| 30 | + let(:log_ctx) { setup_logger_spy } |
| 31 | + let(:log_spy) { retrieve_logger_spy(log_ctx) } |
| 32 | + |
| 33 | + before(:each) do |
| 34 | + # Initialization of appender and logger use to spy, need to be done before executing any code that logs, |
| 35 | + # that's the reason wy to refer the spying logger context before any test. |
| 36 | + log_ctx |
| 37 | + end |
29 | 38 |
|
30 | 39 | before(:each) do |
31 | 40 | allow(LogStash::Settings).to receive(:logger).and_return(double("SettingsLogger").as_null_object) |
|
57 | 66 | it 'does not emit a deprecation warning' do |
58 | 67 | expect(LogStash::Settings.deprecation_logger).to_not receive(:deprecated).with(a_string_including(deprecated_setting_name)) |
59 | 68 | settings.get_setting(deprecated_setting_name).observe_post_process |
| 69 | + log_spy = retrieve_logger_spy(log_ctx) |
| 70 | + expect(log_spy.messages).to be_empty |
60 | 71 | end |
61 | 72 | end |
62 | 73 | end |
|
66 | 77 |
|
67 | 78 | before(:each) do |
68 | 79 | settings.set(deprecated_setting_name, value) |
| 80 | + settings.get_setting(deprecated_setting_name).observe_post_process |
69 | 81 | end |
70 | 82 |
|
71 | 83 | it 'resolves to the value provided for the deprecated alias' do |
72 | 84 | expect(settings.get(canonical_setting_name)).to eq(value) |
73 | 85 | end |
74 | 86 |
|
75 | 87 | it 'logs a deprecation warning' do |
76 | | - expect(LogStash::Settings.deprecation_logger).to have_received(:deprecated).with(a_string_including(deprecated_setting_name)) |
| 88 | + expect(log_spy.messages[0]).to include(deprecated_setting_name) |
77 | 89 | end |
78 | 90 |
|
79 | 91 | include_examples '#validate_value success' |
80 | 92 |
|
81 | 93 | context "#observe_post_process" do |
82 | 94 | it 're-emits the deprecation warning' do |
83 | | - expect(LogStash::Settings.deprecation_logger).to receive(:deprecated).with(a_string_including(deprecated_setting_name)) |
84 | 95 | settings.get_setting(deprecated_setting_name).observe_post_process |
| 96 | + expect(log_spy.messages[0]).to include(deprecated_setting_name) |
85 | 97 | end |
86 | 98 | end |
87 | 99 |
|
|
149 | 161 | end |
150 | 162 |
|
151 | 163 | it 'does not produce a relevant deprecation warning' do |
152 | | - expect(LogStash::Settings.deprecation_logger).to_not have_received(:deprecated).with(a_string_including(deprecated_setting_name)) |
| 164 | + settings.get_setting(deprecated_setting_name).observe_post_process |
| 165 | + expect(log_spy.messages).to be_empty |
153 | 166 | end |
154 | 167 |
|
155 | 168 | include_examples '#validate_value success' |
156 | 169 |
|
157 | 170 | context "#observe_post_process" do |
158 | 171 | it 'does not emit a deprecation warning' do |
159 | | - expect(LogStash::Settings.deprecation_logger).to_not receive(:deprecated).with(a_string_including(deprecated_setting_name)) |
160 | 172 | settings.get_setting(deprecated_setting_name).observe_post_process |
| 173 | + expect(log_spy.messages).to be_empty |
161 | 174 | end |
162 | 175 | end |
163 | 176 | end |
|
171 | 184 | context '#validate_value' do |
172 | 185 | it "raises helpful exception" do |
173 | 186 | expect { settings.get_setting(canonical_setting_name).validate_value } |
174 | | - .to raise_exception(ArgumentError, a_string_including("Both `#{canonical_setting_name}` and its deprecated alias `#{deprecated_setting_name}` have been set. Please only set `#{canonical_setting_name}`")) |
| 187 | + .to raise_exception(java.lang.IllegalStateException, a_string_including("Both `#{canonical_setting_name}` and its deprecated alias `#{deprecated_setting_name}` have been set. Please only set `#{canonical_setting_name}`")) |
175 | 188 | end |
176 | 189 | end |
177 | 190 | end |
178 | 191 |
|
179 | 192 | context 'Settings#get on deprecated alias' do |
180 | 193 | it 'produces a WARN-level message to the logger' do |
181 | | - expect(LogStash::Settings.logger).to receive(:warn).with(a_string_including "setting `#{canonical_setting_name}` has been queried by its deprecated alias `#{deprecated_setting_name}`") |
182 | 194 | settings.get(deprecated_setting_name) |
| 195 | + expect(log_spy.messages[0]).to include("setting `#{canonical_setting_name}` has been queried by its deprecated alias `#{deprecated_setting_name}`") |
183 | 196 | end |
184 | 197 | end |
185 | 198 | end |
0 commit comments