Skip to content

Commit

Permalink
Test that transfer_method can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Dec 27, 2023
1 parent c78f4bf commit 1a6b3cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/unit/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_net_ssh_configuration_options
backend.configure do |ssh|
ssh.pty = true
ssh.connection_timeout = 30
ssh.transfer_method = :sftp
ssh.ssh_options = {
keys: %w(/home/user/.ssh/id_rsa),
forward_agent: false,
Expand All @@ -21,6 +22,7 @@ def test_net_ssh_configuration_options
end

assert_equal 30, backend.config.connection_timeout
assert_equal :sftp, backend.config.transfer_method
assert_equal true, backend.config.pty

assert_equal %w(/home/user/.ssh/id_rsa), backend.config.ssh_options[:keys]
Expand All @@ -29,6 +31,16 @@ def test_net_ssh_configuration_options
assert_instance_of backend::KnownHosts, backend.config.ssh_options[:known_hosts]
end

def test_transfer_method_prohibits_invalid_values
error = assert_raises ArgumentError do
backend.configure do |ssh|
ssh.transfer_method = :nope
end
end

assert_match ":nope is not a valid transfer method", error.message
end

def test_netssh_ext
assert_includes Net::SSH::Config.default_files, "#{Dir.pwd}/.ssh/config"
end
Expand Down
27 changes: 27 additions & 0 deletions test/unit/test_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,33 @@ def test_turning_a_host_into_ssh_options_when_extra_options_are_set
end
end

def test_transfer_method_defaults_to_nil
host = Host.new 'example.com'
assert_nil host.transfer_method
end

def test_transfer_method_can_be_configured
host = Host.new 'example.com'

host.transfer_method = :scp
assert_equal :scp, host.transfer_method

host.transfer_method = :sftp
assert_equal :sftp, host.transfer_method

host.transfer_method = nil
assert_nil host.transfer_method
end

def test_transfer_method_prohibits_invalid_values
host = Host.new 'example.com'

error = assert_raises ArgumentError do
host.transfer_method = :nope
end

assert_match ":nope is not a valid transfer method", error.message
end
end

end

0 comments on commit 1a6b3cd

Please sign in to comment.