Skip to content

Commit e8afdf4

Browse files
committed
Refactor specs after code review
1 parent 51fd369 commit e8afdf4

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@
14991499
end
15001500
end
15011501

1502-
context 'drop_error_types config option' do
1502+
describe 'drop_error_types' do
15031503

1504-
let(:error_type) { 'role_restriction_exception' }
1504+
let(:error_type) { 'index_closed_exception' }
15051505

15061506
let(:options) { super().merge('drop_error_types' => [error_type]) }
15071507

@@ -1511,6 +1511,10 @@
15111511

15121512
let(:error_code) { 403 }
15131513

1514+
let(:event_action_tuples) { subject.map_events(events) }
1515+
1516+
let(:logger) { subject.logger }
1517+
15141518
let(:bulk_response) do
15151519
{
15161520
"took"=>1, "ingest_took"=>11, "errors"=>true, "items"=>
@@ -1528,48 +1532,42 @@
15281532

15291533
context 'DLQ is enabled' do
15301534

1531-
it 'does not write the event to the DLQ' do
1535+
before(:each) do
15321536
allow(subject).to receive(:dlq_enabled?).and_return(true)
1533-
expect(dlq_writer).not_to receive(:write)
1537+
end
15341538

1535-
event_action_tuples = subject.map_events(events)
1539+
it 'does not write the event to the DLQ' do
1540+
expect(dlq_writer).not_to receive(:write)
15361541
subject.send(:submit, event_action_tuples)
15371542
end
15381543
end
15391544

15401545
context 'DLQ is not enabled' do
15411546

1542-
it 'does not write the event to the DLQ' do
1547+
before(:each) do
15431548
allow(subject).to receive(:dlq_enabled?).and_return(false)
1544-
expect(dlq_writer).not_to receive(:write)
1549+
end
15451550

1546-
event_action_tuples = subject.map_events(events)
1551+
it 'does not write the event to the DLQ' do
1552+
expect(dlq_writer).not_to receive(:write)
15471553
subject.send(:submit, event_action_tuples)
15481554
end
15491555
end
15501556

15511557
context 'the error type is not in `silence_errors_in_log`' do
15521558

1553-
let(:logger) { subject.logger }
1554-
15551559
it 'logs the error' do
15561560
expect(logger).to receive(:warn).with(a_string_including("Failed action"), anything).and_call_original
1557-
1558-
event_action_tuples = subject.map_events(events)
15591561
subject.send(:submit, event_action_tuples)
15601562
end
15611563
end
15621564

15631565
context 'the error type is in `silence_errors_in_log`' do
15641566

1565-
let(:logger) { subject.logger }
1566-
15671567
let(:options) { super().merge('silence_errors_in_log' => [error_type]) }
15681568

15691569
it 'does not log the error' do
15701570
expect(logger).not_to receive(:warn)
1571-
1572-
event_action_tuples = subject.map_events(events)
15731571
subject.send(:submit, event_action_tuples)
15741572
end
15751573
end

0 commit comments

Comments
 (0)