aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_alert.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-17 11:08:07 +0100
commit8c8e5ae926e0009743fe92dccb588783640a6022 (patch)
treee23eea583beac0caf5fb3e45a33b4d2ac7796abf /test/tc_mauve_alert.rb
parent79dcf16ec6d229d6c31e055ed8e6a98327526a3a (diff)
* Reminder notifications now take the same path to notify as initial alerts
* Threading tidied -- processor will not do anything unless the timer has frozen * Person#send_alert now tidied and merged with alert_changed * POP3 server only shows alerts relevant to the user * Server now defaults to using an in-memory SQLite database (good for testing) * Server initializes a blank mauve config. * Tests tidied up
Diffstat (limited to 'test/tc_mauve_alert.rb')
-rw-r--r--test/tc_mauve_alert.rb110
1 files changed, 102 insertions, 8 deletions
diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb
index ef80424..f79859f 100644
--- a/test/tc_mauve_alert.rb
+++ b/test/tc_mauve_alert.rb
@@ -1,16 +1,30 @@
$:.unshift "../lib"
-require 'test/unit'
+
+require 'th_mauve'
+require 'th_mauve_resolv'
+
require 'mauve/alert'
+require 'mauve/proto'
+require 'mauve/server'
require 'mauve/configuration'
require 'mauve/configuration_builder'
-require 'th_mauve_resolv'
-require 'pp'
+require 'mauve/configuration_builders'
-class TcMauveAlert < Test::Unit::TestCase
+class TcMauveAlert < Mauve::UnitTest
+ include Mauve
- def test_source_list
+ def setup
+ super
+ setup_database
+ end
+
+ def teardown
+ teardown_database
+ super
+ end
+ def test_source_list
config=<<EOF
source_list "test", %w(test-1.example.com)
@@ -19,9 +33,9 @@ source_list "has_ipv4", "0.0.0.0/0"
source_list "has_ipv6", "2000::/3"
EOF
- Mauve::Configuration.current = Mauve::ConfigurationBuilder.parse(config)
+ Configuration.current = ConfigurationBuilder.parse(config)
- a = Mauve::Alert.new
+ a = Alert.new
a.subject = "www.example.com"
assert( a.in_source_list?("test") )
@@ -35,7 +49,7 @@ EOF
def test_summary
- a = Mauve::Alert.new
+ a = Alert.new
a.summary = "Free swap memory (MB) (memory_swap) is too low"
assert_match(/memory_swap/, a.summary)
@@ -43,5 +57,85 @@ EOF
end
+ def test_raise
+
+ config=<<EOF
+
+alert_group("test") {
+
+}
+
+EOF
+
+ Configuration.current = ConfigurationBuilder.parse(config)
+
+ Server.instance.setup
+
+ a= Alert.new(:source => "test-host",
+ :alert_id => "test" )
+
+ a.raise!
+ end
+
+ def test_alert_reception
+ Server.instance.setup
+
+ update = Proto::AlertUpdate.new
+ update.source = "test-host"
+ message = Proto::Alert.new
+ update.alert << message
+ message.id = "test1"
+ message.summary = "test summary"
+ message.detail = "test detail"
+ message.raise_time = Time.now.to_i
+ message.clear_time = Time.now.to_i+5.minutes
+
+ Alert.receive_update(update, Time.now, "127.0.0.1")
+
+ a = Alert.first(:alert_id => 'test1')
+
+ assert(a.raised?)
+ assert_equal("test-host", a.subject)
+ assert_equal("test-host", a.source)
+ assert_equal("test detail", a.detail)
+ assert_equal("test summary", a.summary)
+
+ end
+
+ def test_alert_ackowledgement
+ person = Mauve::Person.new
+ person.username = "test-user"
+
+ Server.instance.setup
+
+ Mauve::Configuration.current.people[person.username] = person
+
+ alert = Alert.new(
+ :alert_id => "test-acknowledge",
+ :source => "test",
+ :subject => "test"
+ )
+ alert.raise!
+ assert(alert.raised?)
+
+ alert.acknowledge!(person, Time.now + 3.minutes)
+ assert(alert.acknowledged?)
+
+ next_alert = Alert.find_next_with_event
+ assert_equal(next_alert.id, alert.id)
+ assert_equal(Time.now+3.minutes, next_alert.due_at)
+
+ Timecop.freeze(next_alert.due_at)
+
+ alert.poll
+
+ #
+ # The alert should unacknowledge itself.
+ #
+ assert(!alert.acknowledged?)
+
+
+ end
+
end