summaryrefslogtreecommitdiff
path: root/t/test-parser.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-13 16:16:18 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-13 16:16:18 +0000
commit723f2d471679d4f2081b8cca82346f93f906fc26 (patch)
treee978d5ac404e5686d22bdc8717ba24de4a95ed7b /t/test-parser.rb
parentaffe98261e29ec044066c36cf625772eb0f48154 (diff)
added test-case to cover basic file-parsing.
Diffstat (limited to 't/test-parser.rb')
-rwxr-xr-xt/test-parser.rb107
1 files changed, 107 insertions, 0 deletions
diff --git a/t/test-parser.rb b/t/test-parser.rb
new file mode 100755
index 0000000..4c1076a
--- /dev/null
+++ b/t/test-parser.rb
@@ -0,0 +1,107 @@
+#!/usr/bin/ruby -I../parser/ -I./parser/
+
+
+require 'test/unit'
+require 'parser'
+
+
+
+#
+# Unit test for our parser.
+#
+class TestParser < Test::Unit::TestCase
+
+ #
+ # Create the test suite environment: NOP.
+ #
+ def setup
+ end
+
+ #
+ # Destroy the test suite environment: NOP.
+ #
+ def teardown
+ end
+
+
+ #
+ # Test we can create a new parser object - specifically
+ # that it throws exceptions if it is not given a filename
+ # that exists.
+ #
+ def test_init
+
+ #
+ # Missing filename -> Exception
+ #
+ assert_raise ArgumentError do
+ MonitorConfig.new()
+ end
+
+ #
+ # Filename points to file that doesn't exist -> Exception
+ #
+ assert_raise ArgumentError do
+ MonitorConfig.new("/file/doesn't/exist")
+ end
+
+ #
+ # File that exists -> No Exception.
+ #
+ assert_nothing_raised do
+ MonitorConfig.new("/dev/null" )
+ end
+
+ end
+
+
+ #
+ # Test that we can define macros.
+ #
+ def test_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", "kvm2.vm.bytemark.co.uk".
+ #
+ # Before defining it double-check it doesn't exist
+ #
+ assert( !(parser.is_macro?( "FOO" )) )
+
+ parser.define_macro( "FOO is kvm1.vm.bytemark.co.uk and kvm2.vm.bytemark.co.uk." )
+
+
+ #
+ # OK we should now have a single macro defined.
+ #
+ macros = parser.macros
+ assert( macros.size() == 1 )
+
+ #
+ # The macro name "FOO" should exist
+ #
+ assert( parser.is_macro?( "FOO" ) )
+
+ #
+ # The contents of the FOO macro should have the value we expect
+ #
+ val = parser.get_macro_targets( "FOO" )
+ assert( val.size() == 2 )
+ assert( val.include?( "kvm1.vm.bytemark.co.uk" ) )
+ assert( val.include?( "kvm2.vm.bytemark.co.uk" ) )
+ end
+
+
+end