test/test_redis-stat.rb in redis-stat-0.2.5 vs test/test_redis-stat.rb in redis-stat-0.2.6
- old
+ new
@@ -1,11 +1,14 @@
#!/usr/bin/env ruby
+# encoding: utf-8
require 'rubygems'
-require 'test/unit'
+require 'test-unit'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'redis-stat'
+require 'redis'
+require 'stringio'
class TestRedisStat < Test::Unit::TestCase
def test_humanize_number
rs = RedisStat.new
assert_equal '0', rs.send(:humanize_number, 0.00)
@@ -85,10 +88,13 @@
:interval => 10,
:count => nil,
:csv => '/tmp/a.csv',
:style => :ascii
}.sort, options.sort)
+
+ options = RedisStat::Option.parse(%w[--no-color])
+ assert_equal true, options[:mono]
end
def test_option_parse_invalid
[
%w[localhost 0],
@@ -105,16 +111,46 @@
end
def test_start
csv = '/tmp/redis-stat.csv'
cnt = 100
- rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.02, :count => cnt,
+ rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.01, :count => cnt,
:verbose => true, :csv => csv, :auth => 'pw'
rs.start $stdout
assert_equal cnt + 1, File.read(csv).lines.to_a.length
ensure
File.unlink csv
end
-end
+ def test_mono
+ [true, false].each do |mono|
+ rs = RedisStat.new :hosts => %w[localhost] * 5, :interval => 0.02, :count => 20,
+ :verbose => true, :auth => 'pw', :mono => mono
+ output = StringIO.new
+ rs.start output
+ puts output.string
+ assert_equal mono, output.string !~ /\e\[\d*(;\d+)*m/
+ end
+ end
+
+ def test_static_info_of_mixed_versions
+ # prerequisite
+ r1 = Redis.new(:host => 'localhost')
+ r2 = Redis.new(:host => 'localhost', :port => 6380)
+
+ if r1.info['redis_version'] =~ /^2\.4/ && r2.info['redis_version'] =~ /^2\.2/
+ rs = RedisStat.new :hosts => %w[localhost:6380 localhost], :interval => 1, :count => 1,
+ :auth => 'pw', :style => :ascii
+ output = StringIO.new
+ rs.start output
+ vline = output.string.lines.select { |line| line =~ /gcc_version/ }.first
+ puts vline.gsub(/ +/, ' ')
+ assert vline.gsub(/ +/, ' ').include?('| | 4.2.1 |')
+ else
+ raise NotImplementedError.new # FIXME
+ end
+ rescue Redis::CannotConnectError, NotImplementedError
+ pend "redises not ready"
+ end
+end