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 | e52356a2cd913e225f9e4236731edb90dc2d6c76 (patch) | |
| tree | 754d3e60238e959fb7f760d0a8a3863a65a9b0bd | |
| parent | 37bb5d0b2c086194311b5e36d9f4f6356e8ba383 (diff) | |
  Test that the hostname goes in the alert text - if none-specified
| -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 | 
