From f2c2e49a8d0441ceeec84449d3a0d7df63496d24 Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Mon, 6 Sep 2021 18:01:41 +0900 Subject: [PATCH] tests: split async/default shell tests --- tests/test_terraform.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_terraform.py b/tests/test_terraform.py index 232a2c7..3958768 100644 --- a/tests/test_terraform.py +++ b/tests/test_terraform.py @@ -126,10 +126,11 @@ 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"], @@ -137,3 +138,19 @@ def test_shell(terraform, resource, mocker): 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']}", + ] + )