summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-13 23:34:39 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-13 23:34:39 +0000
commit7f0844cc7a6b163a03ac4f30d0010fa44efba0a2 (patch)
tree485524e9097b375b40fa8d6c22346b6306dd535d /t
parentd1a09b1bfe4619615fc7f9dfb814401cc898a3de (diff)
Added more tests - specifically look for default port-saniyt
Diffstat (limited to 't')
-rwxr-xr-xt/test-parser.rb67
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
#