Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
tests: split async/default shell tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Sep 6, 2021
1 parent 071b841 commit f2c2e49
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,31 @@ def test_instances(terraform, resource):
assert list(terraform.instances(resource)) == [expected]


def test_shell(terraform, resource, mocker):
def test_shell_async(terraform, resource, mocker):
data = json.loads(TEST_RESOURCE_STATE)
expected = data["resources"][0]["instances"][0]["attributes"]
mock_connect = mocker.patch("asyncssh.connect", return_value=MagicMock())
mocker.patch("shutil.which", return_value=None)
terraform.run_shell(name=resource)
mock_connect.assert_called_once_with(
host=expected["instance_ip"],
username="ubuntu",
client_keys=ANY,
known_hosts=None,
)


def test_shell_default(terraform, resource, mocker):
data = json.loads(TEST_RESOURCE_STATE)
expected = data["resources"][0]["instances"][0]["attributes"]
mock_run = mocker.patch("subprocess.run")
mocker.patch("shutil.which", return_value="/usr/bin/ssh")
terraform.run_shell(name=resource)
mock_run.assert_called_once_with(
[
"ssh",
"-i",
ANY,
f"ubuntu@{expected['instance_ip']}",
]
)

0 comments on commit f2c2e49

Please sign in to comment.