Skip to content

Commit

Permalink
Add unit tests to check proper events state
Browse files Browse the repository at this point in the history
These where lacking tests, so add them to ensure we don't break them in
the future.
  • Loading branch information
smortex committed Jan 11, 2024
1 parent 80c5a27 commit 2a83d6b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/riemann/tools/syslog_ng_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,49 @@
end
end

context 'with metrics above threshold' do
let(:statistics) do
<<~STATISTICS
dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;queued;204
dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;dropped;0
dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;queued;404
dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;dropped;1
dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;queued;4040
dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;dropped;1000
.
STATISTICS
end

before do
allow(tool).to receive(:report)
tool.tick
end

it 'report correct state with few queued events' do
expect(tool).to have_received(:report).with({ metric: 204, service: 'dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;queued', state: 'ok' })
end

it 'report correct state with some queued events' do
expect(tool).to have_received(:report).with({ metric: 404, service: 'dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;queued', state: 'warning' })
end

it 'report correct state with a lot of queued events' do
expect(tool).to have_received(:report).with({ metric: 4040, service: 'dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;queued', state: 'critical' })
end

it 'report correct state with no dropped events' do
expect(tool).to have_received(:report).with({ metric: 0, service: 'dst.riemann;d_riemann#0;riemann,riemann.example.com,5555;a;dropped', state: 'ok' })
end

it 'report correct state with some dropped events' do
expect(tool).to have_received(:report).with({ metric: 1, service: 'dst.riemann;d_riemann#1;riemann,riemann.example.com,5555;a;dropped', state: 'critical' })
end

it 'report correct state with a lot of dropped events' do
expect(tool).to have_received(:report).with({ metric: 1000, service: 'dst.riemann;d_riemann#2;riemann,riemann.example.com,5555;a;dropped', state: 'critical' })
end
end

context 'with custom formatting' do
before do
ARGV.replace(['--format', '%<source_name>s %<type>s'])
Expand Down

0 comments on commit 2a83d6b

Please sign in to comment.