diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-13 23:34:39 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-13 23:34:39 +0000 |
commit | d5537e06a0f5dc797065f090cf83be0a01de9293 (patch) | |
tree | 485524e9097b375b40fa8d6c22346b6306dd535d /t | |
parent | a63bf20b17b54205a4dbfe685ea16dbc910556bf (diff) |
Added more tests - specifically look for default port-saniyt
Diffstat (limited to 't')
-rwxr-xr-x | t/test-parser.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/t/test-parser.rb b/t/test-parser.rb index 0823be8..9859f89 100755 --- a/t/test-parser.rb +++ b/t/test-parser.rb @@ -1,6 +1,7 @@ #!/usr/bin/ruby1.8 -I./bin/ -I../bin/ +require 'json' require 'test/unit' load 'custodian-enqueue' @@ -219,13 +220,79 @@ class TestParser < Test::Unit::TestCase # The test-type should be set to the correct test. # ret.each do |test| + + # + # Look for valid-seeming JSON with a string match + # assert( test =~ /^\{/ ) assert( test =~ /"test_type":"#{name}"/ ) + + # + # Deserialize and look for a literal match + # + hash = JSON.parse( test ) + assert( hash['test_type'] == name ) + end end end + + # + # Most services define a default port. Ensure that is correct + # + def test_default_ports + + expected = { + "dns" => 53, + "ftp" => 21, + "ldap" => 389, + "jabber" => 5222, + "http" => 80, + "rsync" => 873, + "smtp" => 25, + "ssh" => 22, + } + + + # + # Create the helper + # + parser = MonitorConfig.new("/dev/null" ) + + + # + # Run through our cases + # + expected.each do |test,port| + + # + # Adding a test should return an array - an array of JSON strings. + # + ret = parser.parse_line( "example.vm.bytemark must run #{test} otherwise 'fail'." ) + assert_equal( ret.class.to_s, "Array" ) + assert_equal( ret.size(), 1 ) + + # + # Get the (sole) member of the array + # + addition = ret[0] + + # + # Look for the correct port in our JSON. + # + assert( addition =~ /"test_port":#{port}/ ) + + # + # Deserialize and look for a literal match. + # + hash = JSON.parse( addition ) + assert( hash['test_port'] == port ) + end + end + + # # Comment-handling # |