aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
commit25b32914b72a5f709eca773f3511cc89c2e710c2 (patch)
tree4dab9e78e4c6b49220a837b38d463328c05e2983 /test
parent3185e5d746abda1b7f42ecdbd74ec14359fda3bc (diff)
parentfd23821950f0562a8995735105cd31fdc6d55933 (diff)
merge
Diffstat (limited to 'test')
-rw-r--r--test/tc_mauve_alert.rb47
-rw-r--r--test/tc_mauve_alert_group.rb47
-rw-r--r--test/tc_mauve_configuration_builder.rb72
-rw-r--r--test/tc_mauve_configuration_builders_alert_group.rb13
-rw-r--r--test/tc_mauve_configuration_builders_logger.rb59
-rw-r--r--test/tc_mauve_configuration_builders_notification_method.rb13
-rw-r--r--test/tc_mauve_configuration_builders_person.rb13
-rw-r--r--test/tc_mauve_configuration_builders_server.rb143
-rw-r--r--test/tc_mauve_people_list.rb0
-rw-r--r--test/tc_mauve_source_list.rb78
-rw-r--r--test/th_mauve_resolv.rb30
-rw-r--r--test/ts_mauve.rb20
12 files changed, 535 insertions, 0 deletions
diff --git a/test/tc_mauve_alert.rb b/test/tc_mauve_alert.rb
new file mode 100644
index 0000000..ef80424
--- /dev/null
+++ b/test/tc_mauve_alert.rb
@@ -0,0 +1,47 @@
+$:.unshift "../lib"
+
+require 'test/unit'
+require 'mauve/alert'
+require 'mauve/configuration'
+require 'mauve/configuration_builder'
+require 'th_mauve_resolv'
+require 'pp'
+
+class TcMauveAlert < Test::Unit::TestCase
+
+ def test_source_list
+
+ config=<<EOF
+source_list "test", %w(test-1.example.com)
+
+source_list "has_ipv4", "0.0.0.0/0"
+
+source_list "has_ipv6", "2000::/3"
+EOF
+
+ Mauve::Configuration.current = Mauve::ConfigurationBuilder.parse(config)
+
+ a = Mauve::Alert.new
+ a.subject = "www.example.com"
+
+ assert( a.in_source_list?("test") )
+ assert_equal( %w(test has_ipv4).sort, a.source_lists.sort )
+
+ a.subject = "www2.example.com"
+ assert( a.in_source_list?("has_ipv6") )
+ assert_equal( %w(has_ipv6 has_ipv4).sort, a.source_lists.sort )
+ end
+
+
+ def test_summary
+
+ a = Mauve::Alert.new
+ a.summary = "Free swap memory (MB) (memory_swap) is too low"
+
+ assert_match(/memory_swap/, a.summary)
+
+ end
+
+
+end
+
diff --git a/test/tc_mauve_alert_group.rb b/test/tc_mauve_alert_group.rb
new file mode 100644
index 0000000..12f25ef
--- /dev/null
+++ b/test/tc_mauve_alert_group.rb
@@ -0,0 +1,47 @@
+$:.unshift "../lib"
+
+require 'test/unit'
+require 'mauve/alert_group'
+require 'th_mauve_resolv'
+require 'pp'
+
+class TcMauveAlert < Test::Unit::TestCase
+
+ def test_matches_alert
+
+ alert = Mauve::Alert.new
+
+ alert_group = Mauve::AlertGroup.new("test")
+
+ alert_group.includes = Proc.new { true }
+ assert( alert_group.matches_alert?(alert) )
+
+ alert_group.includes = Proc.new { false }
+ assert( !alert_group.matches_alert?(alert) )
+
+ alert_group.includes = Proc.new { summary =~ /Free swap/ }
+ alert.summary = "Free swap memory (mem_swap) too low"
+ assert( alert_group.matches_alert?(alert) )
+ alert.summary = "Free memory (mem_swap) too low"
+ assert( ! alert_group.matches_alert?(alert) )
+
+ alert_group.includes = Proc.new{ source == 'supportbot' }
+ alert.source = "supportbot"
+ assert( alert_group.matches_alert?(alert) )
+ alert.source = "support!"
+ assert( ! alert_group.matches_alert?(alert) )
+
+ alert_group.includes = Proc.new{ /raid/i.match(summary) }
+ alert.summary = "RAID failure"
+ assert( alert_group.matches_alert?(alert) )
+ alert.summary = "Disc failure"
+ assert( ! alert_group.matches_alert?(alert) )
+ end
+
+
+
+end
+
+
+
+
diff --git a/test/tc_mauve_configuration_builder.rb b/test/tc_mauve_configuration_builder.rb
new file mode 100644
index 0000000..03b86ca
--- /dev/null
+++ b/test/tc_mauve_configuration_builder.rb
@@ -0,0 +1,72 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'pp'
+require 'mauve/configuration_builder'
+
+class TcMauveConfigurationBuildersPeopleAndSourceLists < Test::Unit::TestCase
+
+ def setup
+ Log4r::Logger.new("Mauve").outputters = Log4r::Outputter.stdout
+ end
+
+ def test_people_list
+ config =<<EOF
+people_list "team sky", %w(
+ geraint
+ edvald
+ bradley
+ rigoberto
+ ben
+)
+
+people_list "garmin-cervelo", %w(
+ thor
+ ryder
+ tyler
+ julian
+)
+
+EOF
+ x = nil
+ assert_nothing_raised { x = Mauve::ConfigurationBuilder.parse(config) }
+ assert_equal(2, x.people_lists.keys.length)
+ assert_equal(["team sky","garmin-cervelo"].sort,x.people_lists.keys.sort)
+ assert_equal(%w(geraint edvald bradley rigoberto ben), x.people_lists["team sky"].list)
+
+ end
+
+ def test_duplicate_people_list
+
+ config=<<EOF
+
+people_list "htc-highroad",
+ ["mark c", "mark r", "Lars"]
+
+people_list "htc-highroad",
+ %w(Bernie Danny Lars)
+
+EOF
+ x = nil
+ assert_nothing_raised { x = Mauve::ConfigurationBuilder.parse(config) }
+ assert_equal(1, x.people_lists.keys.length)
+ assert_equal(["mark c","mark r","Lars","Bernie","Danny"].sort, x.people_lists["htc-highroad"].list.sort)
+ end
+
+ def test_source_list
+ config =<<EOF
+source_list "sources", %w(
+ test-1.example.com
+ imaginary.host.example.com
+ 192.168.100.1/24
+ *.imaginary.example.com
+)
+EOF
+
+ x = nil
+ assert_nothing_raised { x = Mauve::ConfigurationBuilder.parse(config) }
+
+ x.source_lists["sources"].resolve
+ end
+
+end
diff --git a/test/tc_mauve_configuration_builders_alert_group.rb b/test/tc_mauve_configuration_builders_alert_group.rb
new file mode 100644
index 0000000..a4104bb
--- /dev/null
+++ b/test/tc_mauve_configuration_builders_alert_group.rb
@@ -0,0 +1,13 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'pp'
+require 'mauve/configuration_builders/alert_group'
+
+class TcMauveConfigurationBuildersNotificationMethod < Test::Unit::TestCase
+
+ def test_load
+
+ end
+
+end
diff --git a/test/tc_mauve_configuration_builders_logger.rb b/test/tc_mauve_configuration_builders_logger.rb
new file mode 100644
index 0000000..8a4bc4e
--- /dev/null
+++ b/test/tc_mauve_configuration_builders_logger.rb
@@ -0,0 +1,59 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'pp'
+require 'mauve/configuration_builders/logger'
+
+class TcMauveConfigurationBuildersLogger < Test::Unit::TestCase
+
+ def test_load
+
+ config=<<EOF
+logger {
+ default_format "%d [ %l ] [ %12.12c ] %m"
+ default_level WARN
+
+ outputter "stdout"
+
+ outputter ("file") {
+ trunc false
+ filename "test.conf"
+ level DEBUG
+ }
+
+}
+EOF
+
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+
+ #
+ # Check that we've got the correct things set
+ #
+ logger = nil
+ assert_nothing_raised { logger = Log4r::Logger.get("Mauve") }
+ assert_equal(2, logger.outputters.length)
+
+ outputter = logger.outputters[0]
+
+ assert_kind_of(Log4r::StdoutOutputter, outputter)
+ assert_equal("%d [ %l ] [ %12.12c ] %m", outputter.formatter.pattern )
+ assert_equal(Log4r::WARN, outputter.level )
+
+ outputter = logger.outputters[1]
+ assert_kind_of(Log4r::FileOutputter, outputter)
+ assert_equal("%d [ %l ] [ %12.12c ] %m", outputter.formatter.pattern )
+ assert_equal(Log4r::DEBUG, outputter.level )
+ assert_equal(false, outputter.trunc )
+ assert_equal("test.conf", outputter.filename )
+ end
+
+ def test_levels
+ #
+ # Make sure our levels match those of log4r.
+ #
+ %w(DEBUG WARN FATAL ERROR INFO).each do |l|
+ assert_equal(Log4r.const_get(l), Mauve::LoggerConstants.const_get(l))
+ end
+ end
+
+end
diff --git a/test/tc_mauve_configuration_builders_notification_method.rb b/test/tc_mauve_configuration_builders_notification_method.rb
new file mode 100644
index 0000000..1ea1e08
--- /dev/null
+++ b/test/tc_mauve_configuration_builders_notification_method.rb
@@ -0,0 +1,13 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'pp'
+require 'mauve/configuration_builders/notification_method'
+
+class TcMauveConfigurationBuildersNotificationMethod < Test::Unit::TestCase
+
+ def test_load
+
+ end
+
+end
diff --git a/test/tc_mauve_configuration_builders_person.rb b/test/tc_mauve_configuration_builders_person.rb
new file mode 100644
index 0000000..cb0b100
--- /dev/null
+++ b/test/tc_mauve_configuration_builders_person.rb
@@ -0,0 +1,13 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'pp'
+require 'mauve/configuration_builders/person'
+
+class TcMauveConfigurationBuildersNotificationMethod < Test::Unit::TestCase
+
+ def test_load
+
+ end
+
+end
diff --git a/test/tc_mauve_configuration_builders_server.rb b/test/tc_mauve_configuration_builders_server.rb
new file mode 100644
index 0000000..4330610
--- /dev/null
+++ b/test/tc_mauve_configuration_builders_server.rb
@@ -0,0 +1,143 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'mauve/configuration_builders/server'
+
+class TcMauveConfigurationBuildersServer < Test::Unit::TestCase
+
+ def test_server_params
+ hostname = "test.example.com"
+ database = "sqlite://./test.db"
+ initial_sleep = 314
+
+ config=<<EOF
+server {
+ hostname "#{hostname}"
+ database "#{database}"
+ initial_sleep #{initial_sleep}
+}
+EOF
+
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+
+ #
+ # Check that we've got the correct things set
+ #
+ s = Mauve::Server.instance
+ assert_equal(hostname, s.hostname)
+ assert_equal(database, s.database)
+ assert_equal(initial_sleep, s.initial_sleep)
+ end
+
+ def test_heartbeat_params
+ destination = "test-backup.example.com"
+ summary = "Mauve blurgh!"
+ detail = "<p>A very interesting test.</p>"
+ raise_after = 1000
+ send_every = 60
+
+ config=<<EOF
+server {
+ heartbeat {
+ destination "#{destination}"
+ summary "#{summary}"
+ detail "#{detail}"
+ raise_after #{raise_after}
+ send_every #{send_every}
+ }
+}
+EOF
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+
+ h = Mauve::Heartbeat.instance
+ assert_equal(detail, h.detail)
+ assert_equal(summary, h.summary)
+ assert_equal(destination, h.destination)
+ assert_equal(raise_after, h.raise_at)
+ assert_equal(send_every, h.sleep_interval)
+ end
+
+ def test_web_interface_params
+ ip = "::"
+ port = 12341
+ document_root = "./"
+ base_url = "http://www.example.com"
+ session_secret = "asd2342"
+ sleep_interval = 32
+
+ config=<<EOF
+server {
+ web_interface {
+ ip "#{ip}"
+ port #{port}
+ document_root "#{document_root}"
+ base_url "#{base_url}"
+ session_secret "#{session_secret}"
+ }
+}
+EOF
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+
+ assert_equal(ip, Mauve::HTTPServer.instance.ip)
+ assert_equal(port, Mauve::HTTPServer.instance.port)
+ assert_equal(document_root, Mauve::HTTPServer.instance.document_root)
+ assert_equal(base_url, Mauve::HTTPServer.instance.base_url)
+ assert_equal(session_secret, Mauve::HTTPServer.instance.session_secret)
+ end
+
+ def test_listener_params
+ ip = "::"
+ port = 12341
+ sleep_interval = 5678
+ config=<<EOF
+server {
+ listener {
+ ip "#{ip}"
+ port #{port}
+ sleep_interval #{sleep_interval}
+ }
+}
+EOF
+
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+ u = Mauve::UDPServer.instance
+ assert_equal(sleep_interval, u.sleep_interval)
+ assert_equal(IPAddr.new(ip), u.ip)
+ assert_equal(port, u.port)
+ end
+
+ def test_notifier_params
+ sleep_interval = 23
+ config=<<EOF
+server {
+ notifier {
+ sleep_interval #{sleep_interval}
+ }
+}
+EOF
+
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+ n = Mauve::Notifier.instance
+ assert_equal(sleep_interval, n.sleep_interval)
+ end
+
+ def test_processor_params
+ transmission_cache_expire_time = 3120
+ sleep_interval = 1235
+
+ config=<<EOF
+server {
+ processor {
+ transmission_cache_expire_time #{transmission_cache_expire_time}
+ sleep_interval #{sleep_interval}
+ }
+}
+EOF
+
+ assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
+ pr = Mauve::Processor.instance
+ assert_equal(transmission_cache_expire_time, pr.transmission_cache_expire_time)
+ assert_equal(sleep_interval, pr.sleep_interval)
+ end
+
+end
diff --git a/test/tc_mauve_people_list.rb b/test/tc_mauve_people_list.rb
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/tc_mauve_people_list.rb
diff --git a/test/tc_mauve_source_list.rb b/test/tc_mauve_source_list.rb
new file mode 100644
index 0000000..d07791f
--- /dev/null
+++ b/test/tc_mauve_source_list.rb
@@ -0,0 +1,78 @@
+$:.unshift "../lib/"
+
+require 'test/unit'
+require 'mauve/source_list'
+require 'th_mauve_resolv'
+require 'pp'
+
+class TcMauveSourceList < Test::Unit::TestCase
+
+ def test_hostname_match
+ sl = Mauve::SourceList.new("test")
+ assert_equal("test", sl.label)
+
+ list = %w(a.example.com b.example.com c.example.com)
+ assert_nothing_raised{ sl += list }
+
+ assert_equal(list, sl.list)
+
+ assert( sl.includes?("a.example.com") )
+ assert( !sl.includes?("d.example.com") )
+ end
+
+ def test_regex_match
+ sl = Mauve::SourceList.new("test")
+
+ assert_nothing_raised{ sl += %w([a-c].example.com *.[d-f].example.com g.example.com) }
+
+ %w(a.example.com www.f.example.com www.a.example.com g.example.com www.other.a.example.com).each do |h|
+ assert( sl.includes?(h), "#{h} did not match")
+ end
+
+ %w(d.example.com a.example.com.other d.example.com).each do |h|
+ assert( !sl.includes?(h), "#{h} matched when it shouldn't have")
+ end
+ end
+
+ def test_ip_match
+ sl = Mauve::SourceList.new("test")
+
+ assert_nothing_raised{ sl += %w(test-1.example.com 1.2.3.5 2001:1:2:3::5 1.2.4.0/24 2001:1:2:4::/64) }
+
+ %w(1.2.3.4 2001:1:2:3::4 1.2.3.5 2001:1:2:3::5 test-2.example.com 1.2.4.23 2001:1:2:4::23 ).each do |h|
+ assert( sl.includes?(h), "#{h} did not match")
+ end
+
+ %w(1.2.3.6 2001:1:2:3::6 test-3.example.com 1.2.5.23 2001:1:2:5::23 ).each do |h|
+ assert( !sl.includes?(h), "#{h} matched when it shouldn't have")
+ end
+
+ end
+
+ def test_uri_match
+ sl = Mauve::SourceList.new("test")
+
+ assert_nothing_raised { sl += "test-1.example.com" }
+
+ %w(https://www.example.com ftp://test-1.example.com http://1.2.3.4 https://[2001:1:2:3::4]).each do |uri|
+ assert( sl.includes?(uri), "#{uri} did not match")
+ end
+
+ %w(http://www.google.com ftp://www2.example.com).each do |uri|
+ assert( !sl.includes?(uri), "#{uri} matched when it shouldn't have" )
+ end
+ end
+
+ def test_ip_crossmatch
+ sl = Mauve::SourceList.new("test")
+ assert_nothing_raised { sl += "test-1.example.com" }
+ assert( sl.includes?("www.example.com"), "www.example.com not found in #{sl.list}" )
+
+ sl = Mauve::SourceList.new("test")
+ assert_nothing_raised { sl += "2001::/3" }
+ assert( sl.includes?("www2.example.com"), "www2.example.com not found in #{sl.list}" )
+ end
+
+end
+
+
diff --git a/test/th_mauve_resolv.rb b/test/th_mauve_resolv.rb
new file mode 100644
index 0000000..98b597b
--- /dev/null
+++ b/test/th_mauve_resolv.rb
@@ -0,0 +1,30 @@
+
+$:.unshift "../lib"
+
+require 'mauve/mauve_resolv'
+
+#
+# This allows us to specify IPs for test hostnames, and also to fall back on
+# regular DNS if that fails.
+#
+
+module Mauve
+ class MauveResolv
+ class << self
+ alias_method :get_ips_for_without_testing, :get_ips_for
+
+ def get_ips_for_with_testing(host)
+ lookup = {
+ "test-1.example.com" => %w(1.2.3.4 2001:1:2:3::4),
+ "test-2.example.com" => %w(1.2.3.5 2001:1:2:3::5),
+ "www.example.com" => %w(1.2.3.4),
+ "www2.example.com" => %w(1.2.3.5 2001:2::2)
+ }
+ lookup[host] || get_ips_for_without_testing(host)
+ end
+
+ alias_method :get_ips_for, :get_ips_for_with_testing
+ end
+ end
+end
+
diff --git a/test/ts_mauve.rb b/test/ts_mauve.rb
new file mode 100644
index 0000000..27284a6
--- /dev/null
+++ b/test/ts_mauve.rb
@@ -0,0 +1,20 @@
+
+$:.unshift "../lib"
+
+require 'test/unit'
+
+%w(
+tc_mauve_configuration_builder.rb
+tc_mauve_configuration_builders_alert_group.rb
+tc_mauve_configuration_builders_logger.rb
+tc_mauve_configuration_builders_notification_method.rb
+tc_mauve_configuration_builders_person.rb
+tc_mauve_configuration_builders_server.rb
+tc_mauve_source_list.rb
+tc_mauve_people_list.rb
+tc_mauve_alert.rb
+tc_mauve_alert_group.rb
+).each do |s|
+ require s
+end
+