diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-03 19:42:20 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-05-03 19:42:20 +0100 |
commit | 58f5a950200f5957307a8552b92ce9e92f948b73 (patch) | |
tree | e7e5dbf2178dfd46e88e8e6d60d6665c58b538fa /test/tc_mauve_alert_group.rb | |
parent | 3a008fd3fff00852533d0df1f597595505373c6b (diff) |
* Person and people lists have now become interchangeable, with notifications
only recording the username, rather than the Person/PeopleList. This means
that notifications in alert groups can use default #during clauses and #every
values from people lists and persons.
* Notify clauses can now take an array of persons/people_lists, and people_lists
can refer to other people lists.
* PeopleList names are now in the same namespace as usernames.
* Tests to go with.
Diffstat (limited to 'test/tc_mauve_alert_group.rb')
-rw-r--r-- | test/tc_mauve_alert_group.rb | 129 |
1 files changed, 125 insertions, 4 deletions
diff --git a/test/tc_mauve_alert_group.rb b/test/tc_mauve_alert_group.rb index 7e7c4dd..92a9d61 100644 --- a/test/tc_mauve_alert_group.rb +++ b/test/tc_mauve_alert_group.rb @@ -1,17 +1,33 @@ $:.unshift "../lib" require 'th_mauve' -require 'mauve/alert_group' require 'th_mauve_resolv' +require 'mauve/alert_group' +require 'mauve/server' +require 'mauve/configuration' +require 'mauve/configuration_builder' +require 'mauve/configuration_builders' require 'pp' class TcMauveAlertGroup < Mauve::UnitTest + include Mauve + + def setup + super + setup_database + end + + def teardown + teardown_database + super + end + def test_matches_alert - alert = Mauve::Alert.new + alert = Alert.new - alert_group = Mauve::AlertGroup.new("test") + alert_group = AlertGroup.new("test") alert_group.includes = Proc.new { true } assert( alert_group.matches_alert?(alert) ) @@ -38,7 +54,112 @@ class TcMauveAlertGroup < Mauve::UnitTest assert( ! alert_group.matches_alert?(alert) ) end - + def test_notify + config=<<EOF +server { + database "sqlite3::memory:" + use_notification_buffer false +} + +notification_method("email") { + debug! + deliver_to_queue [] + disable_normal_delivery! +} + +person ("test1") { + email "test1@example.com" + all { email } + notify { + during { hours_in_day 0 } + } +} + +person ("test2") { + email "test2@example.com" + all { email } + notify { + during { hours_in_day 0,1 } + } +} + +person ("test3") { + email "test3@example.com" + all { email } + notify { + during { true } + } +} + +alert_group("default") { + includes{ true } + notify("test1") + notify("test2") { + during { hours_in_day 1 } + } +} +EOF + Configuration.current = ConfigurationBuilder.parse(config) + notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue + Server.instance.setup + + a = Alert.new( + :alert_id => "test", + :source => "test", + :subject => "test" + ) + + a.raise! + assert_equal("test1@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + + Timecop.freeze(Time.now + 5.minutes) + a.acknowledge!(Configuration.current.people["test2"], Time.now + 5.minutes) + assert_equal(2, notification_buffer.length) + assert_equal(["test1@example.com", "test2@example.com"], notification_buffer.collect{|m| m[2]}.sort) + notification_buffer.pop until notification_buffer.empty? + + Timecop.freeze(Time.now + 5.minutes) + a.clear! + assert_equal(2, notification_buffer.length) + assert_equal(["test1@example.com", "test2@example.com"], notification_buffer.collect{|m| m[2]}.sort) + notification_buffer.pop until notification_buffer.empty? + + # + # If we raise it again, test2 shouldn't get notified. + # + Timecop.freeze(Time.now + 5.minutes) + a.raise! + assert_equal("test1@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + + Timecop.freeze(Time.now + 5.minutes) + a.clear! + assert_equal("test1@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + + # + # Freeze to 1am + # + Timecop.freeze(Time.local(2012,5,2,1,0,0)) + + a.raise! + assert_equal("test2@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + + Timecop.freeze(Time.now + 5.minutes) + a.acknowledge!(Configuration.current.people["test1"], Time.now + 5.minutes) + assert_equal("test2@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + + # + # Test1 shouldn't get notified, even though he ack'd it. + # + Timecop.freeze(Time.now + 5.minutes) + a.clear! + assert_equal("test2@example.com", notification_buffer.pop[2]) + assert(notification_buffer.empty?) + end end |