diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-18 12:06:30 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-18 12:06:30 +0000 |
commit | 83bef1ad6bb484623363f629990f0258177efcb8 (patch) | |
tree | 754d3e60238e959fb7f760d0a8a3863a65a9b0bd /t/test-parser.rb | |
parent | 43db1f9315ac3c3ec42bf02f761fde69ec62c8e2 (diff) |
Test that the hostname goes in the alert text - if none-specified
Diffstat (limited to 't/test-parser.rb')
-rwxr-xr-x | t/test-parser.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/t/test-parser.rb b/t/test-parser.rb index 8de513b..a037448 100755 --- a/t/test-parser.rb +++ b/t/test-parser.rb @@ -562,4 +562,50 @@ class TestParser < Test::Unit::TestCase assert( ret.size == 1 ) end + + + + # + # Test that each test has the hostname in it. + # + def test_alert_expansion + + parser = MonitorConfig.new("/dev/null" ) + + # + # Define a macro - such that a single parsed line will become multiple + # 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." ) + + # + # 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| + # + # Looks like JSON? + # + assert( test =~ /^\{/ ) + assert( test =~ /(kvm1|kvm2|kvm3)\.vm.bytemark.co.uk/ ) + + # + # Decode and look for $hostname in the alert text. + # + hash = JSON.parse( test ) + assert( hash['test_alert'] =~ /kvm/ ) + end + end + end |