aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_alert.rb
diff options
context:
space:
mode:
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