1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
require 'helper'
module SSHKit
module Backend
class TestPrinter < UnitTest
def setup
super
SSHKit.config.output = SSHKit::Formatter::Pretty.new(output)
SSHKit.config.output_verbosity = Logger::DEBUG
Command.any_instance.stubs(:uuid).returns('aaaaaa')
end
def output
@output ||= String.new
end
def printer
@printer ||= Printer.new(Host.new('example.com'))
end
def test_execute
printer.execute 'uname -a'
assert_output_lines(
' INFO [aaaaaa] Running uname -a on example.com',
' DEBUG [aaaaaa] Command: uname -a'
)
end
def test_test_method
assert printer.test('[ -d /some/file ]'), 'test should return true'
assert_output_lines(
' DEBUG [aaaaaa] Running [ -d /some/file ] on example.com',
' DEBUG [aaaaaa] Command: [ -d /some/file ]'
)
end
def test_capture
result = printer.capture 'ls -l'
assert_equal '', result
assert_output_lines(
' DEBUG [aaaaaa] Running ls -l on example.com',
' DEBUG [aaaaaa] Command: ls -l'
)
end
def test_upload
printer.upload! '/some/file', '/remote'
assert_output_lines(
' INFO [aaaaaa] Running /usr/bin/env /some/file /remote on example.com',
' DEBUG [aaaaaa] Command: /usr/bin/env /some/file /remote'
)
end
def test_download
printer.download! 'remote/file', '/local/path'
assert_output_lines(
' INFO [aaaaaa] Running /usr/bin/env remote/file /local/path on example.com',
' DEBUG [aaaaaa] Command: /usr/bin/env remote/file /local/path'
)
end
private
def assert_output_lines(*expected_lines)
assert_equal(expected_lines, output.split("\n"))
end
end
end
end
|