summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-14 11:17:27 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-14 11:17:27 +0000
commita6a96b3ed6140a06f686cb5deb5c80a984bed606 (patch)
tree80b586ba20ab9a8ffc2d3d2f0330c629c334ea37 /t
parent685d9cb4811df3003f230ce5ae0d0f765c736a8b (diff)
Test that we can define macros with just a single host - no " and "
Diffstat (limited to 't')
-rwxr-xr-xt/test-parser.rb86
1 files changed, 86 insertions, 0 deletions
diff --git a/t/test-parser.rb b/t/test-parser.rb
index 9859f89..6a1ba1f 100755
--- a/t/test-parser.rb
+++ b/t/test-parser.rb
@@ -160,6 +160,92 @@ class TestParser < Test::Unit::TestCase
+
+ #
+ # Test that we can define macros with only a single host.
+ #
+ def test_short_macros
+
+ parser = MonitorConfig.new("/dev/null" )
+
+ #
+ # With nothing loaded we should have zero macros - so the
+ # count of our macros hash should be zero
+ #
+ macros = parser.macros
+ assert( macros.empty? )
+ assert( macros.size() == 0 )
+
+
+ #
+ # Define a macro:
+ #
+ # FOO => "kvm1.vm.bytemark.co.uk".
+ #
+ # Before defining it double-check it doesn't exist
+ #
+ assert( !(parser.is_macro?( "FOO" )) )
+
+ #
+ # Add it.
+ #
+ ret = parser.define_macro( "FOO is kvm1.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 == 1 )
+ assert( ret.include?( "kvm1.vm.bytemark.co.uk" ) )
+
+
+ #
+ # OK we should now have a single macro defined.
+ #
+ macros = parser.macros
+ assert( macros.size() == 1 )
+
+ #
+ # Add a macro, using the parser directly.
+ #
+ # Before defining it double-check it doesn't exist
+ #
+ assert( !(parser.is_macro?( "BAR_HOSTS" )) )
+
+ #
+ # Add it.
+ #
+ ret = parser.parse_line( "BAR_HOSTS are example.vm.bytemark.co.uk." )
+
+ #
+ # The return value should be an array containing the single value
+ # we added.
+ #
+ assert( ret.class.to_s == "Array" )
+ assert( ret.size == 1 )
+ assert( ret.include?( "example.vm.bytemark.co.uk" ) )
+
+ #
+ # OK we should now have two macros defined.
+ #
+ macros = parser.macros
+ assert( macros.size() == 2 )
+
+ #
+ # The macro name "BAR_HOSTS" should exist
+ #
+ assert( parser.is_macro?( "BAR_HOSTS" ) )
+
+ #
+ # The contents of the BAR macro should have the single value we expect.
+ #
+ val = parser.get_macro_targets( "BAR_HOSTS" )
+ assert( val.size() == 1 )
+ assert( val.include?( "example.vm.bytemark.co.uk" ) )
+ end
+
+
+
#
# Test that we can define macros.
#