From 723f2d471679d4f2081b8cca82346f93f906fc26 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 13 Nov 2012 16:16:18 +0000 Subject: added test-case to cover basic file-parsing. --- t/test-parser.rb | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 t/test-parser.rb (limited to 't') 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 -- cgit v1.2.1