-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract upload/download tests into module for reuse
- Loading branch information
1 parent
ced903d
commit e75d894
Showing
3 changed files
with
100 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'securerandom' | ||
|
||
module SSHKit | ||
module Backend | ||
module NetsshTransferTests | ||
def test_upload_and_then_capture_file_contents | ||
actual_file_contents = "" | ||
file_name = File.join("/tmp", SecureRandom.uuid) | ||
File.open file_name, 'w+' do |f| | ||
f.write "Some Content\nWith a newline and trailing spaces \n " | ||
end | ||
Netssh.new(a_host) do | ||
upload!(file_name, file_name) | ||
actual_file_contents = capture(:cat, file_name, strip: false) | ||
end.run | ||
assert_equal "Some Content\nWith a newline and trailing spaces \n ", actual_file_contents | ||
end | ||
|
||
def test_upload_within | ||
file_name = SecureRandom.uuid | ||
file_contents = "Some Content" | ||
dir_name = SecureRandom.uuid | ||
actual_file_contents = "" | ||
Netssh.new(a_host) do |_host| | ||
within("/tmp") do | ||
execute :mkdir, "-p", dir_name | ||
within(dir_name) do | ||
upload!(StringIO.new(file_contents), file_name) | ||
end | ||
end | ||
actual_file_contents = capture(:cat, "/tmp/#{dir_name}/#{file_name}", strip: false) | ||
end.run | ||
assert_equal file_contents, actual_file_contents | ||
end | ||
|
||
def test_upload_string_io | ||
file_contents = "" | ||
Netssh.new(a_host) do |_host| | ||
file_name = File.join("/tmp", SecureRandom.uuid) | ||
upload!(StringIO.new('example_io'), file_name) | ||
file_contents = download!(file_name) | ||
end.run | ||
assert_equal "example_io", file_contents | ||
end | ||
|
||
def test_upload_large_file | ||
size = 25 | ||
fills = SecureRandom.random_bytes(1024*1024) | ||
file_name = "/tmp/file-#{size}.txt" | ||
File.open(file_name, 'wb') do |f| | ||
(size).times {f.write(fills) } | ||
end | ||
file_contents = "" | ||
Netssh.new(a_host) do | ||
upload!(file_name, file_name) | ||
file_contents = download!(file_name) | ||
end.run | ||
assert_equal File.open(file_name, 'rb').read, file_contents | ||
end | ||
|
||
def test_upload_via_pathname | ||
file_contents = "" | ||
Netssh.new(a_host) do |_host| | ||
file_name = Pathname.new(File.join("/tmp", SecureRandom.uuid)) | ||
upload!(StringIO.new('example_io'), file_name) | ||
file_contents = download!(file_name) | ||
end.run | ||
assert_equal "example_io", file_contents | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'helper' | ||
require_relative 'netssh_transfer_tests' | ||
|
||
module SSHKit | ||
module Backend | ||
class TestNetsshScp < FunctionalTest | ||
include NetsshTransferTests | ||
|
||
def setup | ||
super | ||
@output = String.new | ||
SSHKit.config.output_verbosity = :debug | ||
SSHKit.config.output = SSHKit::Formatter::SimpleText.new(@output) | ||
SSHKit::Backend::Netssh.configure do |ssh| | ||
ssh.transfer_method = :scp | ||
end | ||
end | ||
|
||
def a_host | ||
VagrantWrapper.hosts['one'] | ||
end | ||
end | ||
end | ||
end |