Skip to content

Commit

Permalink
Test that expected implementation is actually used
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Dec 27, 2023
1 parent 1a6b3cd commit 53ca44e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/functional/backends/test_netssh_scp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def setup
ssh.transfer_method = :scp
end
end

def test_scp_implementation_is_used
Netssh.new(a_host).send(:with_transfer, nil) do |transfer|
assert_instance_of Netssh::ScpTransfer, transfer
end
end
end
end
end
6 changes: 6 additions & 0 deletions test/functional/backends/test_netssh_sftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def setup
ssh.transfer_method = :sftp
end
end

def test_sftp_implementation_is_used
Netssh.new(a_host).send(:with_transfer, nil) do |transfer|
assert_instance_of Netssh::SftpTransfer, transfer
end
end
end
end
end
26 changes: 26 additions & 0 deletions test/unit/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module SSHKit
module Backend
class TestNetssh < UnitTest

def teardown
super
# Reset config to defaults after each test
backend.instance_variable_set :@config, nil
end

def backend
@backend ||= Netssh
end
Expand Down Expand Up @@ -41,6 +47,26 @@ def test_transfer_method_prohibits_invalid_values
assert_match ":nope is not a valid transfer method", error.message
end

def test_transfer_method_defaults_to_scp
assert_equal :scp, backend.config.transfer_method
end

def test_host_can_override_transfer_method
backend.configure do |ssh|
ssh.transfer_method = :scp
end

host = Host.new("fake")
host.transfer_method = :sftp

netssh = backend.new(host)
netssh.stubs(:with_ssh).yields(nil)

netssh.send(:with_transfer, nil) do |transfer|
assert_instance_of Netssh::SftpTransfer, transfer
end
end

def test_netssh_ext
assert_includes Net::SSH::Config.default_files, "#{Dir.pwd}/.ssh/config"
end
Expand Down

0 comments on commit 53ca44e

Please sign in to comment.