aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_alert.rb30
-rw-r--r--test/tc_mauve_alert_changed.rb8
-rw-r--r--test/tc_mauve_configuration_builder.rb2
-rw-r--r--test/tc_mauve_database_peculiarities.rb17
-rw-r--r--test/tc_mauve_generic_http_api_client.rb8
-rw-r--r--test/tc_mauve_sender.rb9
-rw-r--r--test/test_mauve.rb13
-rw-r--r--test/th_mauve.rb10
8 files changed, 56 insertions, 41 deletions
diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb
index 5c6f2bd..3f22030 100644
--- a/test/tc_mauve_alert.rb
+++ b/test/tc_mauve_alert.rb
@@ -11,7 +11,7 @@ require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
-class TcMauveAlert < Mauve::UnitTest
+class TcMauveAlert < Mauve::UnitTest
include Mauve
def setup
@@ -23,7 +23,7 @@ person ("test") {
}
alert_group("default") {
- level URGENT
+ level URGENT
notify("test") {
every 10.minutes
@@ -122,7 +122,7 @@ EOF
next_alert = Alert.find_next_with_event
assert_equal(next_alert.id, alert.id)
- assert_equal(Time.now+3.minutes, next_alert.due_at)
+ assert_equal(Time.now+3.minutes, next_alert.due_at)
Timecop.freeze(Time.now + 3.minutes)
@@ -170,7 +170,7 @@ EOF
assert_equal("test-host", a.source)
assert_equal("test detail", a.detail)
assert_equal("test summary", a.summary)
-
+
end
def test_recieve_update_with_suppression
@@ -203,7 +203,7 @@ EOF
Timecop.freeze(Time.now + 2.minute)
end
-
+
#
# Ten minutes have passed == the suppression should have lapsed.
#
@@ -289,7 +289,7 @@ EOF
assert(!a.suppressed?)
end
-
+
def test_notify_if_needed
Configuration.current = ConfigurationBuilder.parse(@test_config)
Server.instance.setup
@@ -298,7 +298,7 @@ EOF
#
# * the alert has changed state (update_type); or
# * the alert new and "raised".
-
+
alert = Alert.new(
:alert_id => "test_notify_if_needed",
:source => "test",
@@ -320,14 +320,14 @@ EOF
#
# Empty the buffer.
Server.instance.notification_buffer.pop
-
+
Timecop.freeze(Time.now+5)
alert.raise!
#
# Should not re-raise.
#
assert_equal(0, Server.instance.notification_buffer.size, "Notification sent erroneously on second raise.")
-
+
alert.acknowledge!(Mauve::Configuration.current.people["test"])
assert_equal(1, Server.instance.notification_buffer.size, "Wrong number of notifications sent erroneously on acknowledge.")
#
@@ -364,10 +364,10 @@ EOF
Timecop.freeze(Time.now + 10.minutes)
assert_equal(Time.now - 10.minutes, alert.updated_at, "Alert should be last updated before the server instance thinks it started.")
- 5.times do
+ 5.times do
assert(Server.instance.in_initial_sleep?,"Server not in initial sleep when it should be.")
alert.poll
- assert_equal(Server.instance.started_at + Server.instance.initial_sleep, alert.will_raise_at)
+ assert_equal(Server.instance.started_at + Server.instance.initial_sleep, alert.will_raise_at)
assert_equal(0, Server.instance.notification_buffer.size, "Notification sent for old alert")
Timecop.freeze(Time.now + 1.minute)
end
@@ -400,7 +400,7 @@ EOF
assert(alert.cleared?)
alert.poll
assert(alert.cleared?)
- assert(0, Server.instance.notification_buffer.length)
+ assert_equal(0, Server.instance.notification_buffer.length)
end
end
@@ -423,7 +423,7 @@ EOF
Timecop.freeze(Time.now + 5.minutes)
alert.clear!
assert_equal(2, History.all.length)
-
+
#
# OK now we destroy the alert. Destory the histories too.
#
@@ -450,7 +450,7 @@ EOF
assert_equal(Time.now + 5.minutes, alert.suppress_until)
assert(alert.suppressed?)
-
+
alert = Alert.new(
:alert_id => "test_alert_suppression2",
:source => "test",
@@ -490,7 +490,7 @@ EOF
logger_pop
alert.reload
- assert(256, alert.alert_id.length)
+ assert_equal(256, alert.alert_id.length)
end
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
index 679b9bb..6c5520c 100644
--- a/test/tc_mauve_alert_changed.rb
+++ b/test/tc_mauve_alert_changed.rb
@@ -49,15 +49,17 @@ alert_group("test_group") {
}
EOF
+
Configuration.current = ConfigurationBuilder.parse(config)
notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
Server.instance.setup
+
alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
alert.raise!
- reminders = 1
+ reminders = 1
notifications = 1
mins = 0
@@ -146,7 +148,7 @@ EOF
Timecop.freeze(Time.now + 10.minutes)
AlertChanged.all.each{|ac| ac.poll}
assert_equal(2, notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
-
+
#
# OK if we poll the alert now it should be re-raised.
#
@@ -202,7 +204,7 @@ EOF
#
# Raise and clear the alert multiple times.
#
- 5.times do
+ 5.times do
alert.raise!
Timecop.freeze(Time.now + 15.minutes)
alert.clear!
diff --git a/test/tc_mauve_configuration_builder.rb b/test/tc_mauve_configuration_builder.rb
index 1288b5d..8a86e9c 100644
--- a/test/tc_mauve_configuration_builder.rb
+++ b/test/tc_mauve_configuration_builder.rb
@@ -6,10 +6,12 @@ require 'mauve/configuration_builder'
class TcMauveConfigurationBuilder < Mauve::UnitTest
def setup
+ super
setup_logger
end
def teardown
+ super
teardown_logger
end
diff --git a/test/tc_mauve_database_peculiarities.rb b/test/tc_mauve_database_peculiarities.rb
index fa21553..27604a5 100644
--- a/test/tc_mauve_database_peculiarities.rb
+++ b/test/tc_mauve_database_peculiarities.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
$:.unshift "../lib"
require 'th_mauve'
@@ -44,8 +45,10 @@ EOF
%w(UTF-8 WINDOWS-1252 SHIFT-JIS).each do |enc|
x.each do |lang, str|
- assert_nothing_raised("Failed to use iconv to convert to #{enc}") { str = Iconv.conv(enc+"//IGNORE", "utf8", str) }
-
+ assert_nothing_raised("Failed to use iconv to convert to #{enc}") {
+ str = Iconv.conv(enc+"//IGNORE", "utf8", str)
+ }
+
alert = Alert.new(
:alert_id => "#{lang}:#{enc}",
:source => "test",
@@ -69,7 +72,7 @@ class TcMauveDatabasePostgresPeculiarities < TcMauveDatabasePeculiarities
@temp_db = nil
flunk(msg)
end
- # @pg_conn = PGconn.open(:dbname => @temp_db)
+ # @pg_conn = PGconn.open(:dbname => @temp_db)
@db_url = "postgres:///#{@temp_db}"
end
@@ -121,7 +124,7 @@ EOF
assert_equal(1, notification_buffer.length)
notification_buffer.pop
- 10.times do
+ 10.times do
Timecop.freeze(Time.now + 1.minute)
5.times do
AlertChanged.all.each do |ac|
@@ -140,7 +143,7 @@ end
class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities
def setup
super
- # @pg_conn = PGconn.open(:dbname => @temp_db)
+ # @pg_conn = PGconn.open(:dbname => @temp_db)
@db_url = "sqlite3::memory:"
end
@@ -148,8 +151,8 @@ class TcMauveDatabaseSqlite3Peculiarities < TcMauveDatabasePeculiarities
# This just makes sure our mixin has been added to the SqliteAdapter.
#
def test_has_mixin
- assert DataMapper::Adapters::SqliteAdapter.private_instance_methods.include?("with_connection_old")
- assert DataMapper::Adapters::SqliteAdapter.public_instance_methods.include?("synchronize")
+ assert DataMapper::Adapters::SqliteAdapter.private_instance_methods.include?(:with_connection_old)
+ assert DataMapper::Adapters::SqliteAdapter.public_instance_methods.include?(:synchronize)
end
end
diff --git a/test/tc_mauve_generic_http_api_client.rb b/test/tc_mauve_generic_http_api_client.rb
index d8accfa..f3eaf46 100644
--- a/test/tc_mauve_generic_http_api_client.rb
+++ b/test/tc_mauve_generic_http_api_client.rb
@@ -6,7 +6,7 @@ require 'mauve/configuration_builder'
require 'mauve/configuration'
require 'webmock'
-class TcMauveGenericApiClient < Mauve::UnitTest
+class TcMauveGenericApiClient < Mauve::UnitTest
include WebMock::API
include Mauve
@@ -27,7 +27,7 @@ class TcMauveGenericApiClient < Mauve::UnitTest
url = "http://localhost/"
#
- # This sets up two redirects, followed by the answer (below)
+ # This sets up two redirects, followed by the answer (below)
#
2.times do |x|
next_url = url + "#{x}/"
@@ -60,7 +60,7 @@ class TcMauveGenericApiClient < Mauve::UnitTest
#
logger_pop
end
-
+
def test_do_get_with_cache
url = "http://localhost/"
@@ -68,7 +68,7 @@ class TcMauveGenericApiClient < Mauve::UnitTest
# This stubs the request to give out the time
#
stub_request(:get, url).
- to_return( lambda{ {:status => 200, :body => YAML.dump(Time.now), :headers => {}} } )
+ to_return( Proc.new{ {:status => 200, :body => YAML.dump(Time.now), :headers => {}} } )
#
# This reponse should not be cached, the cache-until paramter is "now"
diff --git a/test/tc_mauve_sender.rb b/test/tc_mauve_sender.rb
index 7db06c1..3a98c25 100644
--- a/test/tc_mauve_sender.rb
+++ b/test/tc_mauve_sender.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
$:.unshift "../lib"
require 'th_mauve_resolv'
@@ -9,7 +10,7 @@ require 'locale'
require 'iconv'
-class TcMauveSender < Test::Unit::TestCase
+class TcMauveSender < Test::Unit::TestCase
include Mauve
def setup
@@ -23,7 +24,7 @@ class TcMauveSender < Test::Unit::TestCase
def test_sanitise
Locale.clear
Locale.current = "en_GB.ISO-8859-1"
-
+
#
# Set up a couple of crazy sources.
#
@@ -42,11 +43,11 @@ class TcMauveSender < Test::Unit::TestCase
alert = Mauve::Proto::Alert.new
update.alert << alert
-
+
alert_cleared = Mauve::Proto::Alert.new
update.alert << alert_cleared
alert_cleared.clear_time = Time.now.to_i
-
+
#
# Make sure the update has the correct source
#
diff --git a/test/test_mauve.rb b/test/test_mauve.rb
index a0531d7..81c2a1f 100644
--- a/test/test_mauve.rb
+++ b/test/test_mauve.rb
@@ -1,3 +1,9 @@
+if ENV['COVERAGE']
+ require 'simplecov'
+ SimpleCov.start do
+ add_filter "test/"
+ end
+end
%w(. ..).each do |path|
libdir = File.join(path,"lib")
@@ -8,9 +14,10 @@ require 'pp'
require 'test/unit'
require 'th_mauve'
+
%w(. test).each do |dir|
-Dir.glob(File.join(dir,"tc_*.rb")).each do |s|
- require s
-end
+ Dir.glob(File.join(dir,"tc_*.rb")).each do |s|
+ require s
+ end
end
diff --git a/test/th_mauve.rb b/test/th_mauve.rb
index 49e714b..3c5f048 100644
--- a/test/th_mauve.rb
+++ b/test/th_mauve.rb
@@ -5,14 +5,14 @@ require 'pp'
require 'singleton'
# Taken from
-#
+#
# http://blog.ardes.com/2006/12/11/testing-singletons-with-ruby
#
-class <<Singleton
+class << Singleton
def included_with_reset(klass)
included_without_reset(klass)
- class <<klass
+ class << klass
def reset_instance
Singleton.send :__init__, self
self
@@ -88,7 +88,7 @@ module Mauve
def logger_shift
@outputter.shift
end
-
+
def teardown_logger
logger = Log4r::Logger['Mauve']
return if logger.nil?
@@ -105,7 +105,7 @@ module Mauve
def teardown_database
DataObjects::Pooling.pools.each{|pool| pool.dispose} if defined?(DataObjects::Pooling)
- end
+ end
def setup_time
Timecop.freeze(Time.local(2011,8,1,0,0,0,0))