From 8ca895a7b8f9edd158b7c40d15a81d4483fe623b Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 18 Nov 2023 02:08:43 +0100 Subject: [PATCH] Cloud API: Improve testing --- pyproject.toml | 2 + tests/cluster/test_examples.sh | 4 ++ ...st_examples.py => test_examples_python.py} | 42 ++-------------- tests/cluster/test_examples_shell.py | 48 +++++++++++++++++++ 4 files changed, 57 insertions(+), 39 deletions(-) rename tests/cluster/{test_examples.py => test_examples_python.py} (71%) create mode 100644 tests/cluster/test_examples_shell.py diff --git a/pyproject.toml b/pyproject.toml index bbf51c4c..69b46d9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -240,6 +240,8 @@ markers = [ "examples", "influxdb", "mongodb", + "python", + "shell", "slow", ] diff --git a/tests/cluster/test_examples.sh b/tests/cluster/test_examples.sh index 23f5d951..55696bf8 100644 --- a/tests/cluster/test_examples.sh +++ b/tests/cluster/test_examples.sh @@ -9,6 +9,10 @@ test_cloud_cluster() { source examples/shell/cloud_cluster.sh } +test_cloud_import() { + source examples/shell/cloud_import.sh +} + # Load shUnit2. HERE="$(dirname "$(realpath "$0")")" . ${HERE}/../util/shunit2 diff --git a/tests/cluster/test_examples.py b/tests/cluster/test_examples_python.py similarity index 71% rename from tests/cluster/test_examples.py rename to tests/cluster/test_examples_python.py index 10f5f118..0f321932 100644 --- a/tests/cluster/test_examples.py +++ b/tests/cluster/test_examples_python.py @@ -1,6 +1,5 @@ # Copyright (c) 2023, Crate.io Inc. # Distributed under the terms of the AGPLv3 license, see LICENSE. -import subprocess from pathlib import Path import pytest @@ -9,6 +8,9 @@ import cratedb_toolkit +pytestmark = pytest.mark.python + + ROOT = Path(__file__).parent.parent.parent @@ -36,44 +38,6 @@ def test_example_cloud_cluster_exists_python(mocker, mock_cloud_cluster_exists): main() -def test_example_cloud_cluster_exists_shell(mocker, mock_cloud_cluster_exists, capfd): - """ - Verify that the program `examples/shell/cloud_cluster.sh` works. - In this case, the `ctk` command is mocked completely, so this is nothing serious. - """ - - cratedb_toolkit.configure( - settings_accept_env=True, - ) - - mocker.patch.dict( - "os.environ", - { - "CRATEDB_CLOUD_SUBSCRIPTION_ID": "f33a2f55-17d1-4f21-8130-b6595d7c52db", - "CRATEDB_CLOUD_CLUSTER_NAME": "testcluster", - "CRATEDB_USERNAME": "crate", - }, - ) - - script = ROOT / "tests" / "cluster" / "test_examples.sh" - subprocess.check_call(["bash", script]) # noqa: S603, S607 - - out, err = capfd.readouterr() - - assert "cluster start" in out - assert "shell --command" in out - - """ - assert "Mont Blanc massif" in out - assert "Monte Rosa Alps" in out - assert "Deploying/starting/resuming CrateDB Cloud Cluster: id=None, name=plotz" in err - assert "Cluster information: name=plotz, url=https://plotz.aks1.westeurope.azure.cratedb.net:4200" in err - assert "Successfully acquired cluster" in err - assert "CONNECT OK" in err - assert "SELECT 2 rows in set (0.000 sec)" in err - """ - - @responses.activate def test_example_cloud_cluster_with_deploy(mocker, mock_cloud_cluster_deploy): """ diff --git a/tests/cluster/test_examples_shell.py b/tests/cluster/test_examples_shell.py new file mode 100644 index 00000000..25ffc59e --- /dev/null +++ b/tests/cluster/test_examples_shell.py @@ -0,0 +1,48 @@ +import subprocess +from pathlib import Path + +import pytest + +import cratedb_toolkit + +ROOT = Path(__file__).parent.parent.parent + +pytestmark = pytest.mark.shell + + +def test_example_cloud_cluster_exists_shell(mocker, mock_cloud_cluster_exists, capfd): + """ + Verify that the program `examples/shell/cloud_cluster.sh` works. + In this case, the `ctk` command is mocked completely, so this is nothing serious. + """ + + cratedb_toolkit.configure( + settings_accept_env=True, + ) + + mocker.patch.dict( + "os.environ", + { + "CRATEDB_CLOUD_SUBSCRIPTION_ID": "f33a2f55-17d1-4f21-8130-b6595d7c52db", + "CRATEDB_CLOUD_CLUSTER_NAME": "testcluster", + "CRATEDB_USERNAME": "crate", + }, + ) + + script = ROOT / "tests" / "cluster" / "test_examples.sh" + subprocess.check_call(["bash", script]) # noqa: S603, S607 + + out, err = capfd.readouterr() + + assert "cluster start" in out + assert "shell --command" in out + + """ + assert "Mont Blanc massif" in out + assert "Monte Rosa Alps" in out + assert "Deploying/starting/resuming CrateDB Cloud Cluster: id=None, name=plotz" in err + assert "Cluster information: name=plotz, url=https://plotz.aks1.westeurope.azure.cratedb.net:4200" in err + assert "Successfully acquired cluster" in err + assert "CONNECT OK" in err + assert "SELECT 2 rows in set (0.000 sec)" in err + """