2005-08-06 15:35:25 -04:00
|
|
|
$:.unshift File.dirname(__FILE__) + "/../lib"
|
|
|
|
|
|
|
|
require 'stringio'
|
|
|
|
require 'test/unit'
|
2006-03-05 22:48:35 -05:00
|
|
|
require 'capistrano/command'
|
2005-08-06 15:35:25 -04:00
|
|
|
|
|
|
|
class CommandTest < Test::Unit::TestCase
|
|
|
|
class MockSession
|
|
|
|
def open_channel
|
|
|
|
{ :closed => true, :status => 0 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class MockActor
|
|
|
|
attr_reader :sessions
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@sessions = Hash.new { |h,k| h[k] = MockSession.new }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@actor = MockActor.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_command_executes_on_all_servers
|
2006-03-05 22:48:35 -05:00
|
|
|
command = Capistrano::Command.new(%w(server1 server2 server3),
|
2005-08-06 15:35:25 -04:00
|
|
|
"hello", nil, {}, @actor)
|
|
|
|
assert_equal %w(server1 server2 server3), @actor.sessions.keys.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_command_with_newlines
|
2006-03-05 22:48:35 -05:00
|
|
|
command = Capistrano::Command.new(%w(server1), "hello\nworld", nil, {},
|
2005-08-06 15:35:25 -04:00
|
|
|
@actor)
|
|
|
|
assert_equal "hello\\\nworld", command.command
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_command_with_windows_newlines
|
2006-03-05 22:48:35 -05:00
|
|
|
command = Capistrano::Command.new(%w(server1), "hello\r\nworld", nil, {},
|
2005-08-06 15:35:25 -04:00
|
|
|
@actor)
|
|
|
|
assert_equal "hello\\\nworld", command.command
|
|
|
|
end
|
|
|
|
end
|