mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 23:10:42 +01:00
test: ssh: mock ssh config file exists check
This commit is contained in:
@@ -60,8 +60,11 @@ Host example.com
|
||||
({"url": "ssh://not_in_ssh_config.com"}, "not_in_ssh_config.com"),
|
||||
],
|
||||
)
|
||||
@patch("os.path.exists", return_value=True)
|
||||
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
|
||||
def test_ssh_host_override_from_config(mock_file, config, expected_host):
|
||||
def test_ssh_host_override_from_config(
|
||||
mock_exists, mock_file, config, expected_host
|
||||
):
|
||||
remote = RemoteSSH(None, config)
|
||||
|
||||
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
|
||||
@@ -82,8 +85,9 @@ def test_ssh_host_override_from_config(mock_file, config, expected_host):
|
||||
({"url": "ssh://not_in_ssh_config.com"}, getpass.getuser()),
|
||||
],
|
||||
)
|
||||
@patch("os.path.exists", return_value=True)
|
||||
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
|
||||
def test_ssh_user(mock_file, config, expected_user):
|
||||
def test_ssh_user(mock_exists, mock_file, config, expected_user):
|
||||
remote = RemoteSSH(None, config)
|
||||
|
||||
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
|
||||
@@ -101,8 +105,9 @@ def test_ssh_user(mock_file, config, expected_user):
|
||||
({"url": "ssh://not_in_ssh_config.com:2222", "port": 4321}, 4321),
|
||||
],
|
||||
)
|
||||
@patch("os.path.exists", return_value=True)
|
||||
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
|
||||
def test_ssh_port(mock_file, config, expected_port):
|
||||
def test_ssh_port(mock_exists, mock_file, config, expected_port):
|
||||
remote = RemoteSSH(None, config)
|
||||
|
||||
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
|
||||
@@ -130,9 +135,11 @@ def test_ssh_port(mock_file, config, expected_port):
|
||||
({"url": "ssh://not_in_ssh_config.com"}, None),
|
||||
],
|
||||
)
|
||||
@patch("os.path.exists", return_value=True)
|
||||
@patch("builtins.open", new_callable=mock_open, read_data=mock_ssh_config)
|
||||
def test_ssh_keyfile(mock_file, config, expected_keyfile):
|
||||
def test_ssh_keyfile(mock_exists, mock_file, config, expected_keyfile):
|
||||
remote = RemoteSSH(None, config)
|
||||
|
||||
mock_exists.assert_called_with(os.path.expanduser("~/.ssh/config"))
|
||||
mock_file.assert_called_with(os.path.expanduser("~/.ssh/config"))
|
||||
assert remote.keyfile == expected_keyfile
|
||||
|
||||
Reference in New Issue
Block a user