diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-03-09 13:19:15 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-03-09 13:19:15 +0000 |
commit | a22b8e96ead33b0f97ed5243dbad7f7b6cd5135d (patch) | |
tree | 3fe30365cc9d793c752653a59614b52009ef9336 | |
parent | 7782df6020704f51ee2d6194d8d3b74f28a53401 (diff) |
Prefer single-quotes when you don't need interpolation.
So "foo" is less good than 'foo'.
50 files changed, 325 insertions, 325 deletions
diff --git a/bin/custodian-dequeue b/bin/custodian-dequeue index 48dea57..7a4b629 100755 --- a/bin/custodian-dequeue +++ b/bin/custodian-dequeue @@ -69,23 +69,23 @@ if __FILE__ == $PROGRAM_NAME then begin opts = GetoptLong.new( - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--manual", "-m", GetoptLong::NO_ARGUMENT ], - [ "--fail", "-f", GetoptLong::NO_ARGUMENT ], - [ "--single", "-s", GetoptLong::NO_ARGUMENT ], - [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ] + [ '--help', '-h', GetoptLong::NO_ARGUMENT ], + [ '--manual', '-m', GetoptLong::NO_ARGUMENT ], + [ '--fail', '-f', GetoptLong::NO_ARGUMENT ], + [ '--single', '-s', GetoptLong::NO_ARGUMENT ], + [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ] ) opts.each do |opt, arg| case opt - when "--verbose" then - ENV["VERBOSE"] = "1" - when "--single" then - ENV["SINGLE"] = "1" - when "--fail" then - ENV["FAIL"] = "1" - when "--help" then + when '--verbose' then + ENV['VERBOSE'] = '1' + when '--single' then + ENV['SINGLE'] = '1' + when '--fail' then + ENV['FAIL'] = '1' + when '--help' then $help = true - when "--manual" then + when '--manual' then $manual = true end end diff --git a/bin/custodian-enqueue b/bin/custodian-enqueue index b1be84d..83e462e 100755 --- a/bin/custodian-enqueue +++ b/bin/custodian-enqueue @@ -70,23 +70,23 @@ if __FILE__ == $PROGRAM_NAME then begin opts = GetoptLong.new( - [ "--dump", "-d", GetoptLong::NO_ARGUMENT ], - [ "--test", GetoptLong::NO_ARGUMENT ], - [ "--file", "-f", GetoptLong::REQUIRED_ARGUMENT ], - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--manual","-m", GetoptLong::NO_ARGUMENT ] + [ '--dump', '-d', GetoptLong::NO_ARGUMENT ], + [ '--test', GetoptLong::NO_ARGUMENT ], + [ '--file', '-f', GetoptLong::REQUIRED_ARGUMENT ], + [ '--help', '-h', GetoptLong::NO_ARGUMENT ], + [ '--manual','-m', GetoptLong::NO_ARGUMENT ] ) opts.each do |opt, arg| case opt - when "--dump" then - ENV["DUMP"] = "1" - when "--test" then - ENV["TEST"] = "1" - when "--file" then - ENV["FILE"] = arg - when "--help" then + when '--dump' then + ENV['DUMP'] = '1' + when '--test' then + ENV['TEST'] = '1' + when '--file' then + ENV['FILE'] = arg + when '--help' then $help = true - when "--manual" then + when '--manual' then $manual = true end end diff --git a/bin/custodian-queue b/bin/custodian-queue index 66bf2ba..26f214d 100755 --- a/bin/custodian-queue +++ b/bin/custodian-queue @@ -63,27 +63,27 @@ if __FILE__ == $PROGRAM_NAME then begin opts = GetoptLong.new( - [ "--flush", "-f", GetoptLong::NO_ARGUMENT ], - [ "--help", "-h", GetoptLong::NO_ARGUMENT ], - [ "--manual", "-m", GetoptLong::NO_ARGUMENT ], - [ "--monitor", "-M", GetoptLong::OPTIONAL_ARGUMENT ], - [ "--stats", "-s", GetoptLong::NO_ARGUMENT ] + [ '--flush', '-f', GetoptLong::NO_ARGUMENT ], + [ '--help', '-h', GetoptLong::NO_ARGUMENT ], + [ '--manual', '-m', GetoptLong::NO_ARGUMENT ], + [ '--monitor', '-M', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--stats', '-s', GetoptLong::NO_ARGUMENT ] ) opts.each do |opt, arg| case opt - when "--monitor" then + when '--monitor' then if arg $MONITOR = arg.to_i else $MONITOR = 5000 end - when "--stats" then + when '--stats' then $STATS = true - when "--flush" then + when '--flush' then $FLUSH = true - when "--help" then + when '--help' then $help = true - when "--manual" then + when '--manual' then $manual = true end end diff --git a/lib/custodian/alertfactory.rb b/lib/custodian/alertfactory.rb index 1cb4751..78ad9cf 100644 --- a/lib/custodian/alertfactory.rb +++ b/lib/custodian/alertfactory.rb @@ -46,8 +46,8 @@ module Custodian # def self.create( alert_type, obj ) - raise ArgumentError, "The type of notifier to create cannot be nil" if alert_type.nil? - raise ArgumentError, "The type of notifier to create must be a string" unless alert_type.kind_of? String + raise ArgumentError, 'The type of notifier to create cannot be nil' if alert_type.nil? + raise ArgumentError, 'The type of notifier to create must be a string' unless alert_type.kind_of? String c = @@subclasses[alert_type] if c @@ -112,7 +112,7 @@ module Custodian # Raise an alert. # def raise - puts "NOP" + puts 'NOP' end @@ -121,7 +121,7 @@ module Custodian # Clear an alert. # def clear - puts "NOP" + puts 'NOP' end diff --git a/lib/custodian/alerts/file.rb b/lib/custodian/alerts/file.rb index 5874136..cb04084 100644 --- a/lib/custodian/alerts/file.rb +++ b/lib/custodian/alerts/file.rb @@ -55,7 +55,7 @@ module Custodian # Write the actual message to our target. # def write_message( msg ) - file = File.open(@target, "a") + file = File.open(@target, 'a') file.puts( "#{Time.now} #{msg}" ) file.close @@ -64,7 +64,7 @@ module Custodian - register_alert_type "file" + register_alert_type 'file' diff --git a/lib/custodian/alerts/graphite.rb b/lib/custodian/alerts/graphite.rb index 778b36b..c98f6bf 100644 --- a/lib/custodian/alerts/graphite.rb +++ b/lib/custodian/alerts/graphite.rb @@ -52,7 +52,7 @@ module Custodian # # hostname + test-type # - host = @test.target.gsub(/[\/\\.]/, "_") + host = @test.target.gsub(/[\/\\.]/, '_') test = @test.get_type # @@ -69,7 +69,7 @@ module Custodian end - register_alert_type "graphite" + register_alert_type 'graphite' end diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb index 92c38ee..4c20b08 100644 --- a/lib/custodian/alerts/mauve.rb +++ b/lib/custodian/alerts/mauve.rb @@ -49,7 +49,7 @@ module Custodian require 'mauve/proto' @loaded = true rescue - puts "ERROR Loading mauve libraries!" + puts 'ERROR Loading mauve libraries!' @loaded = false end end @@ -96,14 +96,14 @@ module Custodian # # Lookup the start of the day. # - day_start = @settings.key( "day_start" ).to_i || 10 - day_end = @settings.key( "day_end" ).to_i || 18 + day_start = @settings.key( 'day_start' ).to_i || 10 + day_end = @settings.key( 'day_end' ).to_i || 18 # # In hour suppress # - working_suppress = @settings.key( "working_suppress" ).to_i || 4 - oncall_suppress = @settings.key( "oncall_suppress" ).to_i || 10 + working_suppress = @settings.key( 'working_suppress' ).to_i || 4 + oncall_suppress = @settings.key( 'oncall_suppress' ).to_i || 10 # # If we're Monday-Friday, between the start & end time, then @@ -307,7 +307,7 @@ module Custodian # # Did we get an error? # - return "" unless !resolved.nil? + return '' unless !resolved.nil? # @@ -330,7 +330,7 @@ module Custodian end - register_alert_type "mauve" + register_alert_type 'mauve' diff --git a/lib/custodian/alerts/redis-state.rb b/lib/custodian/alerts/redis-state.rb index f37cef2..27bb2c4 100644 --- a/lib/custodian/alerts/redis-state.rb +++ b/lib/custodian/alerts/redis-state.rb @@ -39,7 +39,7 @@ module Custodian @redis = Redis.new(:host => @target ) rescue - puts "ERROR Loading redis rubygem!" + puts 'ERROR Loading redis rubygem!' end @test = obj @@ -55,16 +55,16 @@ module Custodian return unless( @redis ) tmp = {} - tmp["time"] = Time.now.to_i - tmp["type"] = @test.get_type - tmp["target"] = @test.target - tmp["result"] = "RAISE" - tmp["reason"] = @test.error - tmp["test" ] = @test.to_s - tmp["class" ] = @test.class + tmp['time'] = Time.now.to_i + tmp['type'] = @test.get_type + tmp['target'] = @test.target + tmp['result'] = 'RAISE' + tmp['reason'] = @test.error + tmp['test' ] = @test.to_s + tmp['class' ] = @test.class - @redis.lpush( "recent-tests", tmp.to_json) - @redis.ltrim( "recent-tests", 0, 100 ) + @redis.lpush( 'recent-tests', tmp.to_json) + @redis.ltrim( 'recent-tests', 0, 100 ) end @@ -79,19 +79,19 @@ module Custodian tmp = {} - tmp["time"] = Time.now.to_i - tmp["type"] = @test.get_type - tmp["target"] = @test.target - tmp["result"] = "OK" - tmp["reason"] = "" - tmp["test" ] = @test.to_s - tmp["class" ] = @test.class - - @redis.lpush( "recent-tests", tmp.to_json) - @redis.ltrim( "recent-tests", 0, 100 ) + tmp['time'] = Time.now.to_i + tmp['type'] = @test.get_type + tmp['target'] = @test.target + tmp['result'] = 'OK' + tmp['reason'] = '' + tmp['test' ] = @test.to_s + tmp['class' ] = @test.class + + @redis.lpush( 'recent-tests', tmp.to_json) + @redis.ltrim( 'recent-tests', 0, 100 ) end - register_alert_type "redis" + register_alert_type 'redis' end end diff --git a/lib/custodian/alerts/smtp.rb b/lib/custodian/alerts/smtp.rb index e418031..38ef29e 100644 --- a/lib/custodian/alerts/smtp.rb +++ b/lib/custodian/alerts/smtp.rb @@ -62,14 +62,14 @@ Subject: #{subject} #{body} END_OF_MESSAGE - Net::SMTP.start("127.0.0.1") do |smtp| + Net::SMTP.start('127.0.0.1') do |smtp| smtp.send_message( msg, to, to) end end - register_alert_type "smtp" + register_alert_type 'smtp' diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index c75a050..6942da8 100644 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -73,7 +73,7 @@ module Custodian http.open_timeout = 60 http.read_timeout = 60 - if (url.scheme == "https") + if (url.scheme == 'https') http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end @@ -89,7 +89,7 @@ module Custodian if ( response.code.to_i != 200 ) puts "Status code of #{uri_str} was #{response.code}" - puts "ABORTING" + puts 'ABORTING' exit( 0 ) end @@ -104,11 +104,11 @@ module Custodian end rescue Errno::EHOSTUNREACH => ex - raise ex, "no route to host" + raise ex, 'no route to host' rescue Timeout::Error => ex - raise ex, "timeout" + raise ex, 'timeout' rescue Errno::ECONNREFUSED => ex - raise ex, "connection refused" + raise ex, 'connection refused' end end @@ -135,7 +135,7 @@ module Custodian # # HTTP-fetch # - uri = $1.dup.chomp(".") + uri = $1.dup.chomp('.') text = get_url_contents(uri) text.split( /[\r\n]/ ).each do |line| @@ -411,7 +411,7 @@ module Custodian # def parse_file( filename ) - raise ArgumentError, "Missing configuration file!" if filename.nil? + raise ArgumentError, 'Missing configuration file!' if filename.nil? raise ArgumentError, "File not found: #{@file}" unless File.exist?( filename) # diff --git a/lib/custodian/protocoltest/dns.rb b/lib/custodian/protocoltest/dns.rb index 8d47e14..7f4b997 100644 --- a/lib/custodian/protocoltest/dns.rb +++ b/lib/custodian/protocoltest/dns.rb @@ -64,9 +64,9 @@ module Custodian # # Ensure we had all the data. # - raise ArgumentError, "Missing host to resolve" unless( @resolve_name ) - raise ArgumentError, "Missing type of record to lookup" unless( @resolve_type ) - raise ArgumentError, "Missing expected results" unless( @resolve_expected ) + raise ArgumentError, 'Missing host to resolve' unless( @resolve_name ) + raise ArgumentError, 'Missing type of record to lookup' unless( @resolve_type ) + raise ArgumentError, 'Missing expected results' unless( @resolve_expected ) raise ArgumentError, "Uknown record type: #{@resolve_type}" unless( @resolve_type =~ /^(A|NS|MX|AAAA)$/ ) # @@ -193,7 +193,7 @@ module Custodian - register_test_type "dns" + register_test_type 'dns' diff --git a/lib/custodian/protocoltest/dnsbl.rb b/lib/custodian/protocoltest/dnsbl.rb index 50a3b7b..d307470 100644 --- a/lib/custodian/protocoltest/dnsbl.rb +++ b/lib/custodian/protocoltest/dnsbl.rb @@ -31,7 +31,7 @@ module Custodian # # Ensure the host is an IP address. # - raise ArgumentError, "The target must be an IP address" unless( @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) + raise ArgumentError, 'The target must be an IP address' unless( @host =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) # # See which blacklist(s) we're testing against. @@ -39,7 +39,7 @@ module Custodian if line =~ /via\s+([^\s]+)\s+/ @zones = $1.dup else - @zones = "zen.spamhaus.org" + @zones = 'zen.spamhaus.org' end # @@ -73,7 +73,7 @@ module Custodian # The error is empty. @error = nil - @zones.split( "," ).each do |zone| + @zones.split( ',' ).each do |zone| # # Convert the IP to be looked up. @@ -110,7 +110,7 @@ module Custodian end # register ourselves with the class-factory - register_test_type "dnsbl" + register_test_type 'dnsbl' end end end diff --git a/lib/custodian/protocoltest/ftp.rb b/lib/custodian/protocoltest/ftp.rb index bbed744..921de62 100644 --- a/lib/custodian/protocoltest/ftp.rb +++ b/lib/custodian/protocoltest/ftp.rb @@ -92,7 +92,7 @@ module Custodian - register_test_type "ftp" + register_test_type 'ftp' diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index c43aee3..6ed3c5b 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -79,10 +79,10 @@ module Custodian case line when /\s+must\s(not\s+)?run\s+http(\s+|\.|$)/i then - test_type = "http" + test_type = 'http' when /\s+must\s+(not\s+)?run\s+https(\s+|\.|$)/i then - test_type = "https" + test_type = 'https' else raise ArgumentError, "URL has invalid scheme: #{@line}" end @@ -111,7 +111,7 @@ module Custodian if line =~ /with status ([0-9]+)/ @expected_status = $1.dup else - @expected_status = "200" + @expected_status = '200' end if line =~ /with (IPv[46])/i @@ -158,9 +158,9 @@ module Custodian # def get_type if @url =~ /^https:/ - "https" + 'https' elsif @url =~ /^http:/ - "http" + 'http' else raise ArgumentError, "URL isn't http/https: #{@url}" end @@ -255,7 +255,7 @@ module Custodian end unless @host_override.nil? - c.headers["Host"] = @host_override + c.headers['Host'] = @host_override end c.ssl_verify_host = false @@ -265,7 +265,7 @@ module Custodian # # Set a basic protocol message, for use later. # - protocol_msg = (resolve_mode == :ipv4 ? "IPv4" : "IPv6") + protocol_msg = (resolve_mode == :ipv4 ? 'IPv4' : 'IPv6') begin timeout( period ) do @@ -342,8 +342,8 @@ module Custodian end - register_test_type "http" - register_test_type "https" + register_test_type 'http' + register_test_type 'https' end end diff --git a/lib/custodian/protocoltest/imap.rb b/lib/custodian/protocoltest/imap.rb index 3f338b2..fb80305 100644 --- a/lib/custodian/protocoltest/imap.rb +++ b/lib/custodian/protocoltest/imap.rb @@ -92,7 +92,7 @@ module Custodian - register_test_type "imap" + register_test_type 'imap' diff --git a/lib/custodian/protocoltest/jabber.rb b/lib/custodian/protocoltest/jabber.rb index 1431139..916f15f 100644 --- a/lib/custodian/protocoltest/jabber.rb +++ b/lib/custodian/protocoltest/jabber.rb @@ -90,7 +90,7 @@ module Custodian - register_test_type "jabber" + register_test_type 'jabber' diff --git a/lib/custodian/protocoltest/ldap.rb b/lib/custodian/protocoltest/ldap.rb index aee09e0..a5f6605 100644 --- a/lib/custodian/protocoltest/ldap.rb +++ b/lib/custodian/protocoltest/ldap.rb @@ -92,7 +92,7 @@ module Custodian begin require 'ldap' rescue LoadError - @error = "LDAP library not available - test disabled" + @error = 'LDAP library not available - test disabled' return false end @@ -147,7 +147,7 @@ module Custodian - register_test_type "ldap" + register_test_type 'ldap' end diff --git a/lib/custodian/protocoltest/mx.rb b/lib/custodian/protocoltest/mx.rb index 0df1b5d..61e838c 100644 --- a/lib/custodian/protocoltest/mx.rb +++ b/lib/custodian/protocoltest/mx.rb @@ -103,7 +103,7 @@ module Custodian # failed = 0 passed = 0 - error = "" + error = '' mx.each do |backend| @@ -116,7 +116,7 @@ module Custodian # trim to a sane length & strip newlines. if ! read.nil? read = read[0,255] - read.gsub!(/[\n\r]/, "") + read.gsub!(/[\n\r]/, '') end if read =~ /^220/ @@ -161,7 +161,7 @@ module Custodian - register_test_type "mx" + register_test_type 'mx' diff --git a/lib/custodian/protocoltest/mysql.rb b/lib/custodian/protocoltest/mysql.rb index 135dc38..7abc28f 100644 --- a/lib/custodian/protocoltest/mysql.rb +++ b/lib/custodian/protocoltest/mysql.rb @@ -92,7 +92,7 @@ module Custodian - register_test_type "mysql" + register_test_type 'mysql' diff --git a/lib/custodian/protocoltest/named.rb b/lib/custodian/protocoltest/named.rb index c4e5e8a..4c1b134 100644 --- a/lib/custodian/protocoltest/named.rb +++ b/lib/custodian/protocoltest/named.rb @@ -90,7 +90,7 @@ module Custodian - register_test_type "named" + register_test_type 'named' diff --git a/lib/custodian/protocoltest/openproxy.rb b/lib/custodian/protocoltest/openproxy.rb index da432f0..04fe833 100644 --- a/lib/custodian/protocoltest/openproxy.rb +++ b/lib/custodian/protocoltest/openproxy.rb @@ -92,20 +92,20 @@ module Custodian c.ssl_verify_host = false c.proxy_url = @host c.proxy_tunnel = true - c.url = "http://google.com/" + c.url = 'http://google.com/' c.ssl_verify_peer = false c.timeout = period c.perform @status = c.response_code @content = c.body_str rescue Curl::Err::SSLCACertificateError => x - @error = "SSL-Validation error" + @error = 'SSL-Validation error' return false rescue Curl::Err::TimeoutError - @error = "Timed out fetching page." + @error = 'Timed out fetching page.' return false rescue Curl::Err::TooManyRedirectsError - @error = "Too many redirections (more than 10)" + @error = 'Too many redirections (more than 10)' return false rescue => x @error = "Exception: #{x}" @@ -113,7 +113,7 @@ module Custodian end end rescue Timeout::Error => e - @error = "Timed out during fetch." + @error = 'Timed out during fetch.' return false end @@ -141,7 +141,7 @@ module Custodian - register_test_type "openproxy" + register_test_type 'openproxy' diff --git a/lib/custodian/protocoltest/ping.rb b/lib/custodian/protocoltest/ping.rb index 5a9bf0a..7d3d802 100644 --- a/lib/custodian/protocoltest/ping.rb +++ b/lib/custodian/protocoltest/ping.rb @@ -70,8 +70,8 @@ module Custodian # Find the binary we're going to invoke. # binary = nil - binary = "./bin/multi-ping" - binary = "/usr/bin/multi-ping" if File.exist?( "/usr/bin/multi-ping" ) + binary = './bin/multi-ping' + binary = '/usr/bin/multi-ping' if File.exist?( '/usr/bin/multi-ping' ) if binary.nil? @error = "Failed to find '/usr/bin/multi-ping'" @@ -200,7 +200,7 @@ module Custodian - register_test_type "ping" + register_test_type 'ping' diff --git a/lib/custodian/protocoltest/pop3.rb b/lib/custodian/protocoltest/pop3.rb index 48b2d37..3be34b3 100644 --- a/lib/custodian/protocoltest/pop3.rb +++ b/lib/custodian/protocoltest/pop3.rb @@ -92,8 +92,8 @@ module Custodian - register_test_type "pop3" - register_test_type "pop" + register_test_type 'pop3' + register_test_type 'pop' diff --git a/lib/custodian/protocoltest/postgresql.rb b/lib/custodian/protocoltest/postgresql.rb index 7ce4d70..2dad5cd 100644 --- a/lib/custodian/protocoltest/postgresql.rb +++ b/lib/custodian/protocoltest/postgresql.rb @@ -92,7 +92,7 @@ module Custodian - register_test_type "postgresql" + register_test_type 'postgresql' end diff --git a/lib/custodian/protocoltest/redis.rb b/lib/custodian/protocoltest/redis.rb index 1d732a0..d1815aa 100644 --- a/lib/custodian/protocoltest/redis.rb +++ b/lib/custodian/protocoltest/redis.rb @@ -92,7 +92,7 @@ module Custodian - register_test_type "redis" + register_test_type 'redis' diff --git a/lib/custodian/protocoltest/rsync.rb b/lib/custodian/protocoltest/rsync.rb index 75c27ae..0f3c288 100644 --- a/lib/custodian/protocoltest/rsync.rb +++ b/lib/custodian/protocoltest/rsync.rb @@ -94,7 +94,7 @@ module Custodian - register_test_type "rsync" + register_test_type 'rsync' diff --git a/lib/custodian/protocoltest/smtp.rb b/lib/custodian/protocoltest/smtp.rb index 1d98dca..6a8cd65 100644 --- a/lib/custodian/protocoltest/smtp.rb +++ b/lib/custodian/protocoltest/smtp.rb @@ -90,7 +90,7 @@ module Custodian - register_test_type "smtp" + register_test_type 'smtp' diff --git a/lib/custodian/protocoltest/smtprelay.rb b/lib/custodian/protocoltest/smtprelay.rb index 397c5cb..ef07f82 100644 --- a/lib/custodian/protocoltest/smtprelay.rb +++ b/lib/custodian/protocoltest/smtprelay.rb @@ -61,10 +61,10 @@ module Custodian # Read the hostname for usage in the SMTP-transaction. # def get_hostname - hostname = "localhost.localdomain" + hostname = 'localhost.localdomain' - if File.exist?( "/etc/hostname" ) - File.readlines("/etc/hostname" ).each do |line| + if File.exist?( '/etc/hostname' ) + File.readlines('/etc/hostname' ).each do |line| hostname = line if !line.nil? hostname.chomp! end @@ -87,10 +87,10 @@ module Custodian begin Net::SMTP.start(@host,@port, get_hostname ) do |smtp| - sent = smtp.send_message message, "noreply@bytemark.co.uk", "noreply@bytemark.co.uk" + sent = smtp.send_message message, 'noreply@bytemark.co.uk', 'noreply@bytemark.co.uk' @status = sent.status.to_s - if @status === "250" + if @status === '250' @error = "NOT OK: message sent on #{@host} with status #{@status}" else @error = "OK: message not sent on #{@host} with status #{@status}" @@ -101,10 +101,10 @@ module Custodian # and whether or not we're inverting the test. (eg, 'must not') # - return @inverted if @status == "250" and @inverted - return !@inverted if @status == "250" and !@inverted - return @inverted if @status != "250" and !@inverted - return !@inverted if @status != "250" and @inverted + return @inverted if @status == '250' and @inverted + return !@inverted if @status == '250' and !@inverted + return @inverted if @status != '250' and !@inverted + return !@inverted if @status != '250' and @inverted end # Net SMTP @@ -128,7 +128,7 @@ module Custodian end # register ourselves with the class-factory - register_test_type "smtprelay" + register_test_type 'smtprelay' end end end diff --git a/lib/custodian/protocoltest/ssh.rb b/lib/custodian/protocoltest/ssh.rb index 9b5a608..3d5e9fb 100644 --- a/lib/custodian/protocoltest/ssh.rb +++ b/lib/custodian/protocoltest/ssh.rb @@ -93,7 +93,7 @@ module Custodian - register_test_type "ssh" + register_test_type 'ssh' diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb index 86acb34..39a962d 100644 --- a/lib/custodian/protocoltest/ssl.rb +++ b/lib/custodian/protocoltest/ssl.rb @@ -26,7 +26,7 @@ class SSLCheck # Takes one parameter -- the URL. # def initialize(uri) - raise ArgumentError, "URI must be a string" unless uri.is_a?(String) + raise ArgumentError, 'URI must be a string' unless uri.is_a?(String) @uri = URI.parse(uri) @domain = @uri.host @@ -60,7 +60,7 @@ class SSLCheck # Allows the domain to be set manually. # def domain=(d) - raise ArgumentError, "domain must be a String" unless d.is_a?(String) + raise ArgumentError, 'domain must be a String' unless d.is_a?(String) @domain=d end @@ -76,7 +76,7 @@ class SSLCheck # ones from ALL_TESTS are taken. Anything else is ignored. # def tests=(ts) - raise ArgumentError, "tests must be an Array" unless ts.is_a?(Array) + raise ArgumentError, 'tests must be an Array' unless ts.is_a?(Array) @tests = ts.collect{|t| t.to_sym}.select{|t| ALL_TESTS.include?(t)} @tests @@ -94,7 +94,7 @@ class SSLCheck # Probably not much use here. # def key=(k) - raise ArgumentError, "key must be a String" unless k.is_a?(String) + raise ArgumentError, 'key must be a String' unless k.is_a?(String) if k =~ /-----BEGIN/ @key = OpenSSL::PKey::RSA.new(k) else @@ -127,7 +127,7 @@ class SSLCheck elsif b.is_a?(OpenSSL::X509::Certificate) self.certificate_store.add_cert(b) else - raise ArgumentError, "bundle must be a String, an Array, or an OpenSSL::X509::Certificate" + raise ArgumentError, 'bundle must be a String, an Array, or an OpenSSL::X509::Certificate' end b end @@ -140,7 +140,7 @@ class SSLCheck @certificate_store = OpenSSL::X509::Store.new @certificate_store.set_default_paths - @certificate_store.add_path("/etc/ssl/certs") + @certificate_store.add_path('/etc/ssl/certs') @certificate_store end @@ -412,7 +412,7 @@ module Custodian # Double-check we've got an SSL host # if ! @host =~ /^https:\/\// - puts( "Not an SSL URL" ) + puts( 'Not an SSL URL' ) return true end @@ -442,7 +442,7 @@ module Custodian @error end - register_test_type "https" + register_test_type 'https' end end diff --git a/lib/custodian/protocoltest/tcp.rb b/lib/custodian/protocoltest/tcp.rb index 60c7be7..ca622bb 100644 --- a/lib/custodian/protocoltest/tcp.rb +++ b/lib/custodian/protocoltest/tcp.rb @@ -102,7 +102,7 @@ module Custodian @error = nil if @port.nil? - raise ArgumentError, "Missing port to test against" + raise ArgumentError, 'Missing port to test against' end end @@ -280,7 +280,7 @@ module Custodian # trim to a sane length & strip newlines. if ! read.nil? read = read[0,255] - read.gsub!(/[\n\r]/, "") + read.gsub!(/[\n\r]/, '') end socket.close @@ -317,7 +317,7 @@ module Custodian @error = "TIMEOUT: #{e}" return false end - @error = "Misc failure" + @error = 'Misc failure' false end @@ -334,7 +334,7 @@ module Custodian - register_test_type "tcp" + register_test_type 'tcp' diff --git a/lib/custodian/protocoltest/telnet.rb b/lib/custodian/protocoltest/telnet.rb index b5e0cde..f485191 100644 --- a/lib/custodian/protocoltest/telnet.rb +++ b/lib/custodian/protocoltest/telnet.rb @@ -90,7 +90,7 @@ module Custodian - register_test_type "telnet" + register_test_type 'telnet' diff --git a/lib/custodian/queue.rb b/lib/custodian/queue.rb index b635c1f..12db68d 100644 --- a/lib/custodian/queue.rb +++ b/lib/custodian/queue.rb @@ -6,7 +6,7 @@ begin require library rescue LoadError - ENV["DEBUG"] && puts( "Failed to load the library: #{library}" ) + ENV['DEBUG'] && puts( "Failed to load the library: #{library}" ) end end @@ -25,9 +25,9 @@ module Custodian # def self.create type case type - when "redis" + when 'redis' RedisQueueType.new - when "beanstalk" + when 'beanstalk' BeanstalkQueueType.new else raise "Bad queue-type: #{type}" @@ -39,7 +39,7 @@ module Custodian # Retrieve a job from the queue. # def fetch(_timeout) - raise "Subclasses must implement this method!" + raise 'Subclasses must implement this method!' end @@ -47,7 +47,7 @@ module Custodian # Add a new job to the queue. # def add(_job_string) - raise "Subclasses must implement this method!" + raise 'Subclasses must implement this method!' end @@ -55,7 +55,7 @@ module Custodian # Get the size of the queue # def size? - raise "Subclasses must implement this method!" + raise 'Subclasses must implement this method!' end @@ -63,7 +63,7 @@ module Custodian # Empty the queue # def flush! - raise "Subclasses must implement this method!" + raise 'Subclasses must implement this method!' end end @@ -80,7 +80,7 @@ end # Connect to the server on localhost, unless QUEUE_ADDRESS is set. # def initialize - host = ENV["QUEUE_ADDRESS"] || "127.0.0.1" + host = ENV['QUEUE_ADDRESS'] || '127.0.0.1' @redis = Redis.new( :host => host ) end @@ -96,7 +96,7 @@ end while( true ) - foo, job = @redis.blpop( "queue", :timeout => timeout ) + foo, job = @redis.blpop( 'queue', :timeout => timeout ) if job return job @@ -112,7 +112,7 @@ end # Add a new job to the queue. # def add(job_string) - @redis.rpush( "queue", job_string ) + @redis.rpush( 'queue', job_string ) end @@ -120,7 +120,7 @@ end # How many jobs in the queue? # def size? - @redis.llen( "queue" ) + @redis.llen( 'queue' ) end @@ -128,7 +128,7 @@ end # Empty the queue, discarding all pending jobs. # def flush! - @redis.del( "queue" ) + @redis.del( 'queue' ) end end @@ -144,7 +144,7 @@ end # Connect to the server on localhost, unless QUEUE_ADDRESS is set. # def initialize - host = ENV["QUEUE_ADDRESS"] || "127.0.0.1" + host = ENV['QUEUE_ADDRESS'] || '127.0.0.1' @queue = Beanstalk::Pool.new( ["#{host}:11300" ] ) end @@ -162,7 +162,7 @@ end j.delete return b else - raise "ERRROR" + raise 'ERRROR' end rescue Beanstalk::TimedOut => ex return nil diff --git a/lib/custodian/settings.rb b/lib/custodian/settings.rb index 1739495..c4b11cb 100644 --- a/lib/custodian/settings.rb +++ b/lib/custodian/settings.rb @@ -35,7 +35,7 @@ module Custodian # # Load the configuration file; called only once. # - def _load( file = "/etc/custodian/custodian.cfg" ) + def _load( file = '/etc/custodian/custodian.cfg' ) @parsed = true @settings = {} @@ -48,7 +48,7 @@ module Custodian # # Load and "parse" the key=value content. # - File.open( file, "r" ).each_line do |line| + File.open( file, 'r' ).each_line do |line| next if line.nil? || line =~ /^#/ if line =~ /^(.*)=(.*)$/ key = $1.dup @@ -148,7 +148,7 @@ module Custodian def queue_type _load unless( _loaded? ) - @settings['queue_type'] || "redis" + @settings['queue_type'] || 'redis' end @@ -159,7 +159,7 @@ module Custodian def log_file _load unless( _loaded? ) - @settings['log_file'] || "custodian-dequeue.log" + @settings['log_file'] || 'custodian-dequeue.log' end @@ -169,7 +169,7 @@ module Custodian def alerter _load unless( _loaded? ) - @settings['alerter'] || "file" + @settings['alerter'] || 'file' end @@ -179,7 +179,7 @@ module Custodian def alert_source _load unless( _loaded? ) - @settings['alert_source'] || "Custodian" + @settings['alert_source'] || 'Custodian' end @@ -208,14 +208,14 @@ module Custodian # otherwise per-test defaults. case alert - when "smtp" - "root" - when "mauve" - "alert.bytemark.co.uk" - when "file" - "alerts.log" - when "redis" - "127.0.0.1:6379" + when 'smtp' + 'root' + when 'mauve' + 'alert.bytemark.co.uk' + when 'file' + 'alerts.log' + when 'redis' + '127.0.0.1:6379' else nil end diff --git a/lib/custodian/testfactory.rb b/lib/custodian/testfactory.rb index 748e114..7383ca2 100644 --- a/lib/custodian/testfactory.rb +++ b/lib/custodian/testfactory.rb @@ -31,8 +31,8 @@ module Custodian def self.create( line ) - raise ArgumentError, "The type of test to create cannot be nil" if line.nil? - raise ArgumentError, "The type of test to create must be a string" unless line.kind_of? String + raise ArgumentError, 'The type of test to create cannot be nil' if line.nil? + raise ArgumentError, 'The type of test to create must be a string' unless line.kind_of? String # # The array we return. @@ -46,7 +46,7 @@ module Custodian if line =~ /must\s+(not\s+)?run\s+(\S+)(\s+|\.|$)/ test_type = $2.dup - test_type.chomp!( "." ) + test_type.chomp!( '.' ) if @@subclasses[test_type].nil? raise ArgumentError, "There is no handler registered for the '#{test_type}' test-type" diff --git a/lib/custodian/util/ping.rb b/lib/custodian/util/ping.rb index 771cfd6..cf79754 100644 --- a/lib/custodian/util/ping.rb +++ b/lib/custodian/util/ping.rb @@ -26,8 +26,8 @@ module Custodian # def initialize( hostname ) - raise ArgumentError, "Hostname must not be nil" if hostname.nil? - raise ArgumentError, "Hostname must be a String" unless hostname.kind_of?( String ) + raise ArgumentError, 'Hostname must not be nil' if hostname.nil? + raise ArgumentError, 'Hostname must be a String' unless hostname.kind_of?( String ) @hostname = hostname @resolved = Custodian::Util::DNS.hostname_to_ip( hostname ) @@ -83,7 +83,7 @@ module Custodian return true end else - puts "ERROR: Resolved to neither an IPv6 or IPv4 address." + puts 'ERROR: Resolved to neither an IPv6 or IPv4 address.' end false end diff --git a/lib/custodian/util/timespan.rb b/lib/custodian/util/timespan.rb index 36e8d9e..a033675 100644 --- a/lib/custodian/util/timespan.rb +++ b/lib/custodian/util/timespan.rb @@ -33,7 +33,7 @@ module Custodian # # Ensure within a valid range # - raise ArgumentError, "Integer required for time" unless( desc.kind_of? Integer ) + raise ArgumentError, 'Integer required for time' unless( desc.kind_of? Integer ) raise ArgumentError, "Invalid time: #{desc}" unless( ( desc >= 0 ) && ( desc <= 23 ) ) diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb index 9f66e4a..e5df5e5 100644 --- a/lib/custodian/worker.rb +++ b/lib/custodian/worker.rb @@ -93,7 +93,7 @@ module Custodian # Show a message on STDOUT if "--verbose" was specified. # def log_message( msg ) - puts msg if ENV["VERBOSE" ] + puts msg if ENV['VERBOSE' ] end @@ -104,7 +104,7 @@ module Custodian # def run! while( true ) - log_message( "Waiting for job.." ) + log_message( 'Waiting for job..' ) process_single_job end end @@ -125,8 +125,8 @@ module Custodian # # Ensure that the job is sane. # - raise ArgumentError, "Job was empty" if job.nil? - raise ArgumentError, "Job was not a string" unless job.kind_of?(String) + raise ArgumentError, 'Job was empty' if job.nil? + raise ArgumentError, 'Job was not a string' unless job.kind_of?(String) # # Create test-objects from our class-factory, and process them. @@ -173,7 +173,7 @@ module Custodian result = ! result if test.inverted if result - log_message( "Test succeeed - clearing alert" ) + log_message( 'Test succeeed - clearing alert' ) do_clear( test ) end @@ -240,7 +240,7 @@ module Custodian # Raise an alert, with each registered alerter. # def do_raise( test ) - @alerter.split( "," ).each do |alerter| + @alerter.split( ',' ).each do |alerter| log_message( "Creating alerter: #{alerter}" ) alert = Custodian::AlertFactory.create( alerter, test ) @@ -261,7 +261,7 @@ module Custodian # Clear an alert, with each registered alerter. # def do_clear( test ) - @alerter.split( "," ).each do |alerter| + @alerter.split( ',' ).each do |alerter| log_message( "Creating alerter: #{alerter}" ) alert = Custodian::AlertFactory.create( alerter, test ) @@ -280,7 +280,7 @@ module Custodian # Log the test duration with each registered alerter. # def do_duration( test, duration ) - @alerter.split( "," ).each do |alerter| + @alerter.split( ',' ).each do |alerter| log_message( "Creating alerter: #{alerter}" ) alert = Custodian::AlertFactory.create( alerter, test ) @@ -291,7 +291,7 @@ module Custodian # give the alerter a reference to the settings object. alert.set_settings( @settings ) - alert.duration( duration ) if alert.respond_to? "duration" + alert.duration( duration ) if alert.respond_to? 'duration' end end diff --git a/t/test-custodian-alertfactory.rb b/t/test-custodian-alertfactory.rb index 42873ec..eea35ac 100755 --- a/t/test-custodian-alertfactory.rb +++ b/t/test-custodian-alertfactory.rb @@ -31,8 +31,8 @@ class TestAlertFactory < Test::Unit::TestCase # Ensure we can create each of the two alert types we care about # methods = [] - methods.push( "file" ) - methods.push( "smtp" ) + methods.push( 'file' ) + methods.push( 'smtp' ) # # Mauve + Redis are optional @@ -54,8 +54,8 @@ class TestAlertFactory < Test::Unit::TestCase mauve = false end - methods.push( "redis" ) if redis - methods.push( "mauve" ) if mauve + methods.push( 'redis' ) if redis + methods.push( 'mauve' ) if mauve methods.each do |name| @@ -75,8 +75,8 @@ class TestAlertFactory < Test::Unit::TestCase # Ensure that the object implements the raise() + clear() # methods we mandate. # - assert( obj.respond_to? "raise" ) - assert( obj.respond_to? "clear" ) + assert( obj.respond_to? 'raise' ) + assert( obj.respond_to? 'clear' ) end @@ -84,7 +84,7 @@ class TestAlertFactory < Test::Unit::TestCase # Creating an alert we don't know about is an error # assert_raise ArgumentError do - obj = Custodian::AlertFactory.create( "not found", nil ) + obj = Custodian::AlertFactory.create( 'not found', nil ) end # diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index 49416b3..bbdb8ad 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -51,7 +51,7 @@ class TestCustodianParser < Test::Unit::TestCase def test_period parser = Custodian::Parser.new - result = parser.parse_line( "example.vm.bytemark.co.uk must run ping except between 00-23" ) + result = parser.parse_line( 'example.vm.bytemark.co.uk must run ping except between 00-23' ) assert( result.nil? ) end @@ -72,7 +72,7 @@ class TestCustodianParser < Test::Unit::TestCase parser = Custodian::Parser.new # 1.a. Comment lines return nil. - result = parser.parse_line( "# this is a comment" ) + result = parser.parse_line( '# this is a comment' ) assert( result.nil? ) # 1.b. Non-strings are an error @@ -94,7 +94,7 @@ class TestCustodianParser < Test::Unit::TestCase parser = Custodian::Parser.new # 2.a. Comment lines return nil. tmp = [] - tmp.push( "# This is a comment.." ) + tmp.push( '# This is a comment..' ) assert( parser.parse_lines( tmp ).nil? ) # 2.b. Adding a test will return an array of test-objects. @@ -172,8 +172,8 @@ EOF # Input text # text = [] - text.push( "FOO is kvm1.vm.bytemark.co.uk." ) - text.push( "FOO2 is kvm2.vm.bytemark.co.uk." ) + text.push( 'FOO is kvm1.vm.bytemark.co.uk.' ) + text.push( 'FOO2 is kvm2.vm.bytemark.co.uk.' ) # # Test the parser with this text @@ -203,8 +203,8 @@ EOF # Input text to parse. # text = [] - text.push( "FOO is kvm1.vm.bytemark.co.uk." ) - text.push( "FOO is kvm2.vm.bytemark.co.uk." ) + text.push( 'FOO is kvm1.vm.bytemark.co.uk.' ) + text.push( 'FOO is kvm2.vm.bytemark.co.uk.' ) # # Test the parser with this text @@ -241,7 +241,7 @@ EOF # Expand a line - which should result in no change # as the line does not involve a known-macro # - in_txt = "example.bytemark.co.uk must run smtp." + in_txt = 'example.bytemark.co.uk must run smtp.' out_txt = parser.expand_macro( in_txt ) # @@ -255,14 +255,14 @@ EOF # # Now define a macro # - parser.parse_line( "TARGET is example1.bytemark.co.uk and example2.bytemark.co.uk." ) + parser.parse_line( 'TARGET is example1.bytemark.co.uk and example2.bytemark.co.uk.' ) macros = parser.macros assert( !macros.empty? ) # # Now we have a two-host macro, repeat the expansion # - ret = parser.expand_macro( "TARGET must run smtp on 25." ) + ret = parser.expand_macro( 'TARGET must run smtp on 25.' ) # # The result should be an array @@ -284,12 +284,12 @@ EOF # test data # data = { - "http://example must run http." => true, - "http://example must run http with status 200." => true, + 'http://example must run http.' => true, + 'http://example must run http with status 200.' => true, "http://example must run http with content 'bar'." => true, - "http://example must run http following redirects." => true, - "http://example must run http not following redirects." => false, - "http://example must run http not following redirect." => false, + 'http://example must run http following redirects.' => true, + 'http://example must run http not following redirects.' => false, + 'http://example must run http not following redirect.' => false, } data.each do |str,follow| @@ -325,10 +325,10 @@ EOF # test data # data = { - "http://example must run http." => true, - "http://example must run http with status 200." => true, + 'http://example must run http.' => true, + 'http://example must run http with status 200.' => true, "http://example must run http with content 'bar'." => true, - "http://example must run http without cache busting." => false, + 'http://example must run http without cache busting.' => false, } data.each do |str,cb| @@ -365,13 +365,13 @@ EOF # test data # data = { - "foo must run rsync." => nil, - "foo must run redis." => nil, - "foo must not run ping." => nil, - "foo must not run ssh otherwise 'fail'" => "fail", - "foo must not run ssh otherwise 'fail'." => "fail", - "foo must run redis otherwise 'memorystorage service is dead'" => "memorystorage service is dead", - "foo must run ping otherwise 'don't you love me?'" => "don" + 'foo must run rsync.' => nil, + 'foo must run redis.' => nil, + 'foo must not run ping.' => nil, + "foo must not run ssh otherwise 'fail'" => 'fail', + "foo must not run ssh otherwise 'fail'." => 'fail', + "foo must run redis otherwise 'memorystorage service is dead'" => 'memorystorage service is dead', + "foo must run ping otherwise 'don't you love me?'" => 'don' } # diff --git a/t/test-custodian-queue.rb b/t/test-custodian-queue.rb index 0170ef1..bec83e2 100755 --- a/t/test-custodian-queue.rb +++ b/t/test-custodian-queue.rb @@ -40,7 +40,7 @@ class TestCustodianQueue < Test::Unit::TestCase # creation will fail assert_raise RuntimeError do - t = Custodian::QueueType.create( "foo" ) + t = Custodian::QueueType.create( 'foo' ) end end @@ -50,7 +50,7 @@ class TestCustodianQueue < Test::Unit::TestCase def test_redis q = nil assert_nothing_raised do - q = Custodian::QueueType.create( "redis" ) + q = Custodian::QueueType.create( 'redis' ) end # @@ -68,7 +68,7 @@ class TestCustodianQueue < Test::Unit::TestCase def test_beanstalkd q = nil assert_nothing_raised do - q = Custodian::QueueType.create( "redis" ) + q = Custodian::QueueType.create( 'redis' ) end # diff --git a/t/test-custodian-settings.rb b/t/test-custodian-settings.rb index 0347e7c..1923b0f 100755 --- a/t/test-custodian-settings.rb +++ b/t/test-custodian-settings.rb @@ -50,13 +50,13 @@ class TestConfigurationSingleton < Test::Unit::TestCase assert( a.class == Fixnum ) # store a number - settings._store( "retry_delay", 5 ) + settings._store( 'retry_delay', 5 ) a = settings.retry_delay assert( a.class == Fixnum ) assert( a == 5 ) # store a string - settings._store( "retry_delay", "35" ) + settings._store( 'retry_delay', '35' ) a = settings.retry_delay assert( a.class == Fixnum ) assert( a == 35 ) @@ -68,13 +68,13 @@ class TestConfigurationSingleton < Test::Unit::TestCase assert( a.class == Fixnum ) # store a number - settings._store( "timeout", 5 ) + settings._store( 'timeout', 5 ) a = settings.timeout assert( a.class == Fixnum ) assert( a == 5 ) # store a string - settings._store( "timeout", "35" ) + settings._store( 'timeout', '35' ) a = settings.timeout assert( a.class == Fixnum ) assert( a == 35 ) diff --git a/t/test-custodian-testfactory.rb b/t/test-custodian-testfactory.rb index b067ab8..af3e3b3 100755 --- a/t/test-custodian-testfactory.rb +++ b/t/test-custodian-testfactory.rb @@ -45,25 +45,25 @@ class TestTestFactory < Test::Unit::TestCase def test_ftp_uri assert_nothing_raised do - assert( Custodian::TestFactory.create( "ftp.example.com must run ftp." ) ) - assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp." ) ) - assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp on 21." ) ) + assert( Custodian::TestFactory.create( 'ftp.example.com must run ftp.' ) ) + assert( Custodian::TestFactory.create( 'ftp://ftp.example.com/ must run ftp.' ) ) + assert( Custodian::TestFactory.create( 'ftp://ftp.example.com/ must run ftp on 21.' ) ) assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp on 21 otherwise 'xxx'." ) ) end - assert( Custodian::TestFactory.create( "ftp.example.com must run ftp." )[0].target == "ftp.example.com" ) - assert( Custodian::TestFactory.create( "ftp://ftp.example.com/ must run ftp." )[0].target == "ftp.example.com" ) + assert( Custodian::TestFactory.create( 'ftp.example.com must run ftp.' )[0].target == 'ftp.example.com' ) + assert( Custodian::TestFactory.create( 'ftp://ftp.example.com/ must run ftp.' )[0].target == 'ftp.example.com' ) # # Test the port detection # data = { - "foo must run ftp." => "21", - "ftp://ftp.example.com/ must run ftp." => "21", - "foo must run ftp on 1 otherwise 'x'." => "1", - "foo must run ftp on 33 otherwise" => "33", + 'foo must run ftp.' => '21', + 'ftp://ftp.example.com/ must run ftp.' => '21', + "foo must run ftp on 1 otherwise 'x'." => '1', + 'foo must run ftp on 33 otherwise' => '33', } # @@ -76,7 +76,7 @@ class TestTestFactory < Test::Unit::TestCase assert( obj.kind_of? Array ) assert( ! obj.empty? ) - assert_equal( obj[0].get_type, "ftp" ) + assert_equal( obj[0].get_type, 'ftp' ) assert_equal( obj[0].port.to_s, prt ) end @@ -91,11 +91,11 @@ class TestTestFactory < Test::Unit::TestCase # def test_port_detection data = { - "foo must run ftp." => "21", - "foo must run ssh." => "22", - "foo must run mysql otherwise 'alert'" => "3306", - "foo must run redis otherwise 'alert'" => "6379", - "foo must run mysql on 33 otherwise 'alert'" => "33", + 'foo must run ftp.' => '21', + 'foo must run ssh.' => '22', + "foo must run mysql otherwise 'alert'" => '3306', + "foo must run redis otherwise 'alert'" => '6379', + "foo must run mysql on 33 otherwise 'alert'" => '33', } # @@ -124,26 +124,26 @@ class TestTestFactory < Test::Unit::TestCase assert_nothing_raised do - assert( Custodian::TestFactory.create( "example.com must run rsync." ) ) - assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync." ) ) - assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync on 333." ) ) + assert( Custodian::TestFactory.create( 'example.com must run rsync.' ) ) + assert( Custodian::TestFactory.create( 'ftp://example.com/ must run rsync.' ) ) + assert( Custodian::TestFactory.create( 'ftp://example.com/ must run rsync on 333.' ) ) assert( Custodian::TestFactory.create( "ftp://example.com/ must run rsync on 3311 otherwise 'xxx'." ) ) end - assert( Custodian::TestFactory.create( "rsync.example.com must run rsync." )[0].target == - "rsync.example.com" ) - assert( Custodian::TestFactory.create( "rsync://rsync.example.com/ must run rsync." )[0].target == - "rsync.example.com" ) + assert( Custodian::TestFactory.create( 'rsync.example.com must run rsync.' )[0].target == + 'rsync.example.com' ) + assert( Custodian::TestFactory.create( 'rsync://rsync.example.com/ must run rsync.' )[0].target == + 'rsync.example.com' ) # # Test the ports # data = { - "foo must run rsync." => "873", - "rsync://foo/ must run rsync." => "873", - "foo must run rsync on 1 otherwise 'x'." => "1", - "foo must run rsync on 33 otherwise" => "33", + 'foo must run rsync.' => '873', + 'rsync://foo/ must run rsync.' => '873', + "foo must run rsync on 1 otherwise 'x'." => '1', + 'foo must run rsync on 33 otherwise' => '33', } # @@ -191,7 +191,7 @@ class TestTestFactory < Test::Unit::TestCase # Missing expected results # assert_raise ArgumentError do - assert( Custodian::TestFactory.create( "a.ns.bytemark.co.uk must run dns for www.bytemark.co.uk resolving NS " ) ) + assert( Custodian::TestFactory.create( 'a.ns.bytemark.co.uk must run dns for www.bytemark.co.uk resolving NS ' ) ) end end @@ -205,9 +205,9 @@ class TestTestFactory < Test::Unit::TestCase assert_nothing_raised do - assert( Custodian::TestFactory.create( "example.com must not run rsync." ) ) - assert( Custodian::TestFactory.create( "ftp://example.com/ must not run rsync." ) ) - assert( Custodian::TestFactory.create( "ftp://example.com/ must not run rsync on 333." ) ) + assert( Custodian::TestFactory.create( 'example.com must not run rsync.' ) ) + assert( Custodian::TestFactory.create( 'ftp://example.com/ must not run rsync.' ) ) + assert( Custodian::TestFactory.create( 'ftp://example.com/ must not run rsync on 333.' ) ) end @@ -215,11 +215,11 @@ class TestTestFactory < Test::Unit::TestCase # Test some inversions # data = { - "foo must run rsync." => false, - "rsync://foo/ must run rsync." => false, - "foo must run ping otherwise" => false, - "foo must not run ping otherwise" => true, - "foo must not run ssh otherwise" => true, + 'foo must run rsync.' => false, + 'rsync://foo/ must run rsync.' => false, + 'foo must run ping otherwise' => false, + 'foo must not run ping otherwise' => true, + 'foo must not run ssh otherwise' => true, } # @@ -292,13 +292,13 @@ class TestTestFactory < Test::Unit::TestCase a = [] - a.push( "test.host.example.com must run ftp.") - a.push( "ftp://test.host.example.com/ must run ftp.") - a.push( "ftp://test.host.example.com/foo must run ftp.") - a.push( "test.host.example.com must run ping.") + a.push( 'test.host.example.com must run ftp.') + a.push( 'ftp://test.host.example.com/ must run ftp.') + a.push( 'ftp://test.host.example.com/foo must run ftp.') + a.push( 'test.host.example.com must run ping.') a.push( "test.host.example.com must run dns for bytemark.co.uk resolving NS as '80.68.80.26;85.17.170.78;80.68.80.27'.") - a.push( "rsync://test.host.example.com must run rsync.") - a.push( "rsync://test.host.example.com must run rsync.") + a.push( 'rsync://test.host.example.com must run rsync.') + a.push( 'rsync://test.host.example.com must run rsync.') a.each do |entry| assert_nothing_raised do @@ -306,7 +306,7 @@ class TestTestFactory < Test::Unit::TestCase assert(obj) assert( obj.kind_of? Array ) assert( ! obj.empty? ) - assert_equal( "test.host.example.com", obj[0].target ) + assert_equal( 'test.host.example.com', obj[0].target ) end end end diff --git a/t/test-custodian-util-bytemark.rb b/t/test-custodian-util-bytemark.rb index 9296dcb..30bb480 100755 --- a/t/test-custodian-util-bytemark.rb +++ b/t/test-custodian-util-bytemark.rb @@ -38,15 +38,15 @@ class TestBytemarkUtil < Test::Unit::TestCase # # Hosts inside the Bytemark network # - "80.68.85.48" => true, - "2001:41c8:125:46::10" => true, + '80.68.85.48' => true, + '2001:41c8:125:46::10' => true, # # Hosts outside the Bytemark network # - "127.0.0.1" => false, - "192.168.1.1" => false, - "2a00:1450:400c:c00::93" => false, + '127.0.0.1' => false, + '192.168.1.1' => false, + '2a00:1450:400c:c00::93' => false, } diff --git a/t/test-custodian-util-dns.rb b/t/test-custodian-util-dns.rb index f226efe..2582d94 100755 --- a/t/test-custodian-util-dns.rb +++ b/t/test-custodian-util-dns.rb @@ -30,26 +30,26 @@ class TestDNSUtil < Test::Unit::TestCase # def test_lookup - details = Custodian::Util::DNS.hostname_to_ip( "bytemark.co.uk" ) - assert( ( details == "2001:41c9:0:1019:81::80" ) || - ( details == "80.68.81.80" ) ) + details = Custodian::Util::DNS.hostname_to_ip( 'bytemark.co.uk' ) + assert( ( details == '2001:41c9:0:1019:81::80' ) || + ( details == '80.68.81.80' ) ) - details = Custodian::Util::DNS.hostname_to_ip( "www.bytemark.co.uk" ) - assert( ( details == "2001:41c9:0:1019:81::80" ) || - ( details == "80.68.81.80" ) ) + details = Custodian::Util::DNS.hostname_to_ip( 'www.bytemark.co.uk' ) + assert( ( details == '2001:41c9:0:1019:81::80' ) || + ( details == '80.68.81.80' ) ) - details = Custodian::Util::DNS.hostname_to_ip( "ipv4.steve.org.uk" ) - assert( details == "80.68.84.103" ) + details = Custodian::Util::DNS.hostname_to_ip( 'ipv4.steve.org.uk' ) + assert( details == '80.68.84.103' ) - details = Custodian::Util::DNS.hostname_to_ip( "ipv6.steve.org.uk" ) - assert( details == "2001:41c8:10b:103::10" ) + details = Custodian::Util::DNS.hostname_to_ip( 'ipv6.steve.org.uk' ) + assert( details == '2001:41c8:10b:103::10' ) # # Failure case # - details = Custodian::Util::DNS.hostname_to_ip( "this.doesnot.exist" ) + details = Custodian::Util::DNS.hostname_to_ip( 'this.doesnot.exist' ) assert( details.nil? ) end @@ -63,19 +63,19 @@ class TestDNSUtil < Test::Unit::TestCase # # IPv6 lookup # - details = Custodian::Util::DNS.ip_to_hostname( "2001:41c9:0:1019:81::80" ) + details = Custodian::Util::DNS.ip_to_hostname( '2001:41c9:0:1019:81::80' ) assert( details =~ /bytemark(-?hosting)?\.(com|eu|co\.uk)$/i ) # # IPv4 lookup # - details = Custodian::Util::DNS.ip_to_hostname( "80.68.81.80" ) + details = Custodian::Util::DNS.ip_to_hostname( '80.68.81.80' ) assert( details =~ /bytemark(-?hosting)?\.(com|eu|co\.uk)$/i ) # # Bogus lookup - should return nil. # - details = Custodian::Util::DNS.ip_to_hostname( "800.683.853.348" ) + details = Custodian::Util::DNS.ip_to_hostname( '800.683.853.348' ) assert( details.nil? ) end diff --git a/t/test-custodian-util-ping.rb b/t/test-custodian-util-ping.rb index bf8ac43..e01ef8d 100755 --- a/t/test-custodian-util-ping.rb +++ b/t/test-custodian-util-ping.rb @@ -34,7 +34,7 @@ class TestPingUtil < Test::Unit::TestCase # Normal construction works. # assert_nothing_raised do - Custodian::Util::Ping.new("foo") + Custodian::Util::Ping.new('foo') end # @@ -64,7 +64,7 @@ class TestPingUtil < Test::Unit::TestCase # def test_lookup_ipv4 - helper = Custodian::Util::Ping.new( "ipv4.steve.org.uk" ) + helper = Custodian::Util::Ping.new( 'ipv4.steve.org.uk' ) assert( helper.is_ipv4? ) assert( ! helper.is_ipv6? ) @@ -76,7 +76,7 @@ class TestPingUtil < Test::Unit::TestCase # def test_lookup_ipv6 - helper = Custodian::Util::Ping.new( "ipv6.steve.org.uk" ) + helper = Custodian::Util::Ping.new( 'ipv6.steve.org.uk' ) assert( helper.is_ipv6? ) assert( ! helper.is_ipv4? ) end diff --git a/t/test-custodian-util-timespan.rb b/t/test-custodian-util-timespan.rb index 29e9b83..210a532 100755 --- a/t/test-custodian-util-timespan.rb +++ b/t/test-custodian-util-timespan.rb @@ -114,7 +114,7 @@ class TestTimeSpanUtil < Test::Unit::TestCase # def test_simple_cases # 8am-5pm - assert(Custodian::Util::TimeSpan.inside?( "8am", "5am", 12 )) + assert(Custodian::Util::TimeSpan.inside?( '8am', '5am', 12 )) assert(Custodian::Util::TimeSpan.inside?( 8, 17, 12 )) end @@ -125,25 +125,25 @@ class TestTimeSpanUtil < Test::Unit::TestCase def test_midnight_cases # 9pm-2am - assert(Custodian::Util::TimeSpan.inside?( "9pm", "2am", 22 )) - assert(Custodian::Util::TimeSpan.inside?( "9pm", "2am", "10pm" )) + assert(Custodian::Util::TimeSpan.inside?( '9pm', '2am', 22 )) + assert(Custodian::Util::TimeSpan.inside?( '9pm', '2am', '10pm' )) assert(Custodian::Util::TimeSpan.inside?( 21, 2, 22 )) - assert(Custodian::Util::TimeSpan.inside?( 21, 2, "10pm" )) + assert(Custodian::Util::TimeSpan.inside?( 21, 2, '10pm' )) # 10pm-3am - assert(Custodian::Util::TimeSpan.inside?( "10pm", "3am", 22 )) + assert(Custodian::Util::TimeSpan.inside?( '10pm', '3am', 22 )) assert(Custodian::Util::TimeSpan.inside?( 22, 3, 22 )) assert(Custodian::Util::TimeSpan.inside?( 22, 3, 22 )) - assert(Custodian::Util::TimeSpan.inside?( 22, 3, "10pm" )) + assert(Custodian::Util::TimeSpan.inside?( 22, 3, '10pm' )) # 11pm-5am - assert(Custodian::Util::TimeSpan.inside?( "11pm", "5am", 23 )) + assert(Custodian::Util::TimeSpan.inside?( '11pm', '5am', 23 )) assert(Custodian::Util::TimeSpan.inside?( 23, 5, 23 )) - assert(Custodian::Util::TimeSpan.inside?( "11pm", "5am", "11pm" )) + assert(Custodian::Util::TimeSpan.inside?( '11pm', '5am', '11pm' )) # midnight-3am - assert( Custodian::Util::TimeSpan.inside?( "0", "3am", 1 )) - assert( Custodian::Util::TimeSpan.inside?( "0", "3am", "1am" )) + assert( Custodian::Util::TimeSpan.inside?( '0', '3am', 1 )) + assert( Custodian::Util::TimeSpan.inside?( '0', '3am', '1am' )) end @@ -154,18 +154,18 @@ class TestTimeSpanUtil < Test::Unit::TestCase # def test_inclusive - open = "4pm" - close = "6pm" + open = '4pm' + close = '6pm' # The hours + the middle should be inside assert( Custodian::Util::TimeSpan.inside?( open, close, 16 ) ) - assert( Custodian::Util::TimeSpan.inside?( open, close, "4pm" ) ) + assert( Custodian::Util::TimeSpan.inside?( open, close, '4pm' ) ) assert( Custodian::Util::TimeSpan.inside?( open, close, 17 ) ) - assert( Custodian::Util::TimeSpan.inside?( open, close, "5pm" ) ) + assert( Custodian::Util::TimeSpan.inside?( open, close, '5pm' ) ) assert( Custodian::Util::TimeSpan.inside?( open, close, 18 ) ) - assert( Custodian::Util::TimeSpan.inside?( open, close, "6pm" ) ) + assert( Custodian::Util::TimeSpan.inside?( open, close, '6pm' ) ) # @@ -177,19 +177,19 @@ class TestTimeSpanUtil < Test::Unit::TestCase # # That is true for the string-versions too # - assert( ! Custodian::Util::TimeSpan.inside?( open, close, "3pm" ) ) - assert( ! Custodian::Util::TimeSpan.inside?( open, close, "7pm" ) ) + assert( ! Custodian::Util::TimeSpan.inside?( open, close, '3pm' ) ) + assert( ! Custodian::Util::TimeSpan.inside?( open, close, '7pm' ) ) # # Random hours should be outside too. # assert( ! Custodian::Util::TimeSpan.inside?( open, close, 3 ) ) - assert( ! Custodian::Util::TimeSpan.inside?( open, close, "3am" ) ) + assert( ! Custodian::Util::TimeSpan.inside?( open, close, '3am' ) ) assert( ! Custodian::Util::TimeSpan.inside?( open, close, 7 ) ) - assert( ! Custodian::Util::TimeSpan.inside?( open, close, "7am" ) ) + assert( ! Custodian::Util::TimeSpan.inside?( open, close, '7am' ) ) assert( ! Custodian::Util::TimeSpan.inside?( open, close, 9 ) ) - assert( ! Custodian::Util::TimeSpan.inside?( open, close, "9am" ) ) + assert( ! Custodian::Util::TimeSpan.inside?( open, close, '9am' ) ) end diff --git a/t/test-http-vs-https.rb b/t/test-http-vs-https.rb index b320777..ab44ffc 100755 --- a/t/test-http-vs-https.rb +++ b/t/test-http-vs-https.rb @@ -42,13 +42,13 @@ class TestTestName < Test::Unit::TestCase test = nil assert_nothing_raised do - test = Custodian::TestFactory.create( "http://example.com/ must run http." ) + test = Custodian::TestFactory.create( 'http://example.com/ must run http.' ) end assert( test ) assert( test.kind_of? Array ) assert( ! test.empty? ) - assert_equal( test[0].get_type, "http" ) + assert_equal( test[0].get_type, 'http' ) end @@ -59,13 +59,13 @@ class TestTestName < Test::Unit::TestCase test = nil assert_nothing_raised do - test = Custodian::TestFactory.create( "https://example.com/ must run https." ) + test = Custodian::TestFactory.create( 'https://example.com/ must run https.' ) end assert( test ) assert( test.kind_of? Array ) assert( ! test.empty? ) - assert_equal( test[0].get_type, "https" ) + assert_equal( test[0].get_type, 'https' ) end @@ -76,19 +76,19 @@ class TestTestName < Test::Unit::TestCase assert_raise ArgumentError do - Custodian::TestFactory.create( "https://example.com/ must run http." ) + Custodian::TestFactory.create( 'https://example.com/ must run http.' ) end assert_raise ArgumentError do - Custodian::TestFactory.create( "http://example.com/ must run https." ) + Custodian::TestFactory.create( 'http://example.com/ must run https.' ) end assert_nothing_raised do - Custodian::TestFactory.create( "http://example.com/ must run http." ) + Custodian::TestFactory.create( 'http://example.com/ must run http.' ) end assert_nothing_raised do - Custodian::TestFactory.create( "https://example.com/ must run https." ) + Custodian::TestFactory.create( 'https://example.com/ must run https.' ) end end diff --git a/t/test-ldap-probe.rb b/t/test-ldap-probe.rb index 5273b31..63e95a3 100755 --- a/t/test-ldap-probe.rb +++ b/t/test-ldap-probe.rb @@ -34,7 +34,7 @@ class TestLDAPProbe < Test::Unit::TestCase assert( test.kind_of? Array ) assert( ! test.empty? ) - assert_equal( test[0].get_type, "ldap" ) + assert_equal( test[0].get_type, 'ldap' ) end @@ -47,7 +47,7 @@ class TestLDAPProbe < Test::Unit::TestCase # test data # data = [ - "foo.example.com must run ldap on 389.", + 'foo.example.com must run ldap on 389.', "foo.example.com must run ldap with username 'test'.", "foo.example.com must run ldap with uername 'test' with password 'x'." ] diff --git a/t/test-suite b/t/test-suite index 02df298..26ddb1f 100755 --- a/t/test-suite +++ b/t/test-suite @@ -27,7 +27,7 @@ dir = File.dirname(__FILE__) # # Load each file in the same directory. # -Dir.glob(File.join(dir,"t*.rb")).each do |test| +Dir.glob(File.join(dir,'t*.rb')).each do |test| require test end |