spec/lib/flapjack/data/event_spec.rb in flapjack-0.9.6 vs spec/lib/flapjack/data/event_spec.rb in flapjack-1.0.0rc1
- old
+ new
@@ -20,22 +20,15 @@
'acknowledgement_id' => '1234',
'duration' => (60 * 60),
'tags' => ['dev'] }
}
- before(:each) do
- Flapjack::Data::Event.instance_variable_set('@previous_base_time_str', nil)
- end
-
context 'class' do
it "returns the next event (blocking, archiving)" do
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(event_data.to_json)
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:expire)
result = Flapjack::Data::Event.next('events', :block => true,
:archive_events => true, :redis => mock_redis)
expect(result).to be_an_instance_of(Flapjack::Data::Event)
@@ -51,13 +44,10 @@
end
it "returns the next event (non-blocking, archiving)" do
expect(mock_redis).to receive(:rpoplpush).
with('events', /^events_archive:/).and_return(event_data.to_json)
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:expire)
result = Flapjack::Data::Event.next('events', :block => false,
:archive_events => true, :redis => mock_redis)
expect(result).to be_an_instance_of(Flapjack::Data::Event)
@@ -74,13 +64,10 @@
it "rejects invalid event JSON (archiving)" do
bad_event_json = '{{{'
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(bad_event_json)
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:multi)
expect(mock_redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
expect(mock_redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
expect(mock_redis).to receive(:exec)
expect(mock_redis).to receive(:expire)
@@ -105,13 +92,10 @@
it "rejects an event with missing '#{required_key}' key (archiving)" do
bad_event_data = event_data.clone
bad_event_data.delete(required_key)
bad_event_json = bad_event_data.to_json
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(bad_event_json)
expect(mock_redis).to receive(:multi)
expect(mock_redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
expect(mock_redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
@@ -140,13 +124,10 @@
bad_event_data = event_data.clone
bad_event_data[required_key] = {'hello' => 'there'}
bad_event_json = bad_event_data.to_json
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(bad_event_json)
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:multi)
expect(mock_redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
expect(mock_redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
expect(mock_redis).to receive(:exec)
expect(mock_redis).to receive(:expire)
@@ -173,13 +154,10 @@
['time', 'details', 'perfdata', 'acknowledgement_id', 'duration', 'tags'].each do |optional_key|
it "rejects an event with invalid '#{optional_key}' key (archiving)" do
bad_event_data = event_data.clone
bad_event_data[optional_key] = {'hello' => 'there'}
bad_event_json = bad_event_data.to_json
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(bad_event_json)
expect(mock_redis).to receive(:multi)
expect(mock_redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
expect(mock_redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
@@ -208,13 +186,10 @@
['type', 'state'].each do |key|
it "it matches case-insensitively for #{key} (archiving)" do
case_event_data = event_data.clone
case_event_data[key] = event_data[key].upcase
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(case_event_data.to_json)
expect(mock_redis).to receive(:expire)
result = Flapjack::Data::Event.next('events', :block => true,
@@ -237,13 +212,10 @@
['time', 'duration'].each do |key|
it "it accepts an event with a numeric #{key} key (archiving)" do
num_event_data = event_data.clone
num_event_data[key] = event_data[key].to_i.to_s
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(num_event_data.to_json)
expect(mock_redis).to receive(:expire)
result = Flapjack::Data::Event.next('events', :block => true,
@@ -266,12 +238,9 @@
bad_event_data = event_data.clone
bad_event_data[key] = 'NaN'
bad_event_json = bad_event_data.to_json
expect(mock_redis).to receive(:brpoplpush).
with('events', /^events_archive:/, 0).and_return(bad_event_json)
- expect(Flapjack::Data::Migration).to receive(:purge_expired_archive_index).with(:redis => mock_redis)
- expect(mock_redis).to receive(:sadd).
- with('known_events_archive_keys', /^events_archive:/)
expect(mock_redis).to receive(:multi)
expect(mock_redis).to receive(:lrem).with(/^events_archive:/, 1, bad_event_json)
expect(mock_redis).to receive(:lpush).with(/^events_rejected:/, bad_event_json)
expect(mock_redis).to receive(:exec)
expect(mock_redis).to receive(:expire)