summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-13 23:26:08 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-13 23:26:08 +0000
commit564520e96acd3caf2891a7603b2c1e568aaeebc0 (patch)
tree8ade9a682507ba9d222ad497c847335c32557764
parent021bfa5d6343e0d0b63fe16180a190c27c12a529 (diff)
Considerably more test-cases.
-rwxr-xr-xt/test-parser.rb112
1 files changed, 110 insertions, 2 deletions
diff --git a/t/test-parser.rb b/t/test-parser.rb
index c061cbe..9965e65 100755
--- a/t/test-parser.rb
+++ b/t/test-parser.rb
@@ -80,7 +80,18 @@ class TestParser < Test::Unit::TestCase
#
assert( !(parser.is_macro?( "FOO" )) )
- parser.define_macro( "FOO is kvm1.vm.bytemark.co.uk and kvm2.vm.bytemark.co.uk." )
+ #
+ # Add it.
+ #
+ ret = parser.define_macro( "FOO is kvm1.vm.bytemark.co.uk and kvm2.vm.bytemark.co.uk." )
+
+ #
+ # The return value should be an array containing the values we added.
+ #
+ assert( ret.class.to_s == "Array" )
+ assert( ret.size == 2 )
+ assert( ret.include?( "kvm1.vm.bytemark.co.uk" ) )
+ assert( ret.include?( "kvm2.vm.bytemark.co.uk" ) )
#
@@ -89,6 +100,7 @@ class TestParser < Test::Unit::TestCase
macros = parser.macros
assert( macros.size() == 1 )
+
#
# The macro name "FOO" should exist
#
@@ -110,7 +122,20 @@ class TestParser < Test::Unit::TestCase
#
assert( !(parser.is_macro?( "BAR" )) )
- parser.parse_line( "BAR is example.vm.bytemark.co.uk and www.bytemark.co.uk." )
+ #
+ # Add it.
+ #
+ ret = parser.parse_line( "BAR is example.vm.bytemark.co.uk and www.bytemark.co.uk." )
+
+ #
+ # The return value should be an array containing the values
+ # we added.
+ #
+ assert( ret.class.to_s == "Array" )
+ assert( ret.size == 2 )
+ assert( ret.include?( "example.vm.bytemark.co.uk" ) )
+ assert( ret.include?( "www.bytemark.co.uk" ) )
+
#
# OK we should now have two macros defined.
@@ -133,4 +158,87 @@ class TestParser < Test::Unit::TestCase
end
+
+ #
+ # Test that we can define macros.
+ #
+ def test_adding_tests
+
+ parser = MonitorConfig.new("/dev/null" )
+
+ #
+ # Adding a test should return an array - an array of JSON strings.
+ #
+ ret = parser.parse_line( "example.vm.bytemark must run ssh otherwise 'I hate you'." )
+ assert_equal( ret.class.to_s, "Array" )
+ assert_equal( ret.size(), 1 )
+
+ #
+ # Define a macro - such that a single added test will become
+ # several indivual tests.
+ #
+ parser.parse_line( "MACRO is kvm1.vm.bytemark.co.uk and kvm1.vm.bytemark.co.uk and kvm3.vm.bytemark.co.uk." )
+ assert( parser.is_macro?( "MACRO") )
+
+ #
+ # Now add a ping-test against that macro
+ #
+ ret = parser.parse_line( "MACRO must run ping otherwise 'ping failure'." )
+
+ #
+ # The resulting array should contain three JSON strings.
+ #
+ assert_equal( ret.class.to_s, "Array" )
+ assert_equal( ret.size(),3 )
+
+ #
+ # Ensure we look like valid JSON, and contains the correct hostnames.
+ #
+ ret.each do |test|
+ assert( test =~ /^\{/ )
+ assert( test =~ /(kvm1|kvm2|kvm3)\.vm.bytemark.co.uk/ )
+ end
+
+ #
+ # Now add more alerts, and ensure we find something sane:
+ #
+ # 1. The addition should be JSON.
+ #
+ # 2. The addition should have the correct test-type
+ #
+ %w( dns ftp http https jabber ldap rsync ssh smtp ).each do |name|
+ ret = parser.parse_line( "MACRO must run #{name} otherwise '#{name} failure'." )
+
+ #
+ # The resulting array should contain three JSON strings.
+ #
+ assert_equal( ret.class.to_s, "Array" )
+ assert_equal( ret.size(),3 )
+
+ #
+ # The test-type should be set to the correct test.
+ #
+ ret.each do |test|
+ assert( test =~ /^\{/ )
+ assert( test =~ /"test_type":"#{name}"/ )
+ end
+ end
+ end
+
+
+ #
+ # Comment-handling
+ #
+ def test_adding_comments
+
+ parser = MonitorConfig.new("/dev/null" )
+
+ #
+ # Adding comments should result in a nil return value.
+ #
+ assert( parser.parse_line( "# This is a comment" ).nil? )
+ assert( parser.parse_line( "\n" ).nil? )
+ assert( parser.parse_line( "" ).nil? )
+ assert( parser.parse_line( nil ).nil? )
+ end
end