Skip to content

Commit

Permalink
Cloud API: Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jul 6, 2024
1 parent 8be8c08 commit 8ca895a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 39 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ markers = [
"examples",
"influxdb",
"mongodb",
"python",
"shell",
"slow",
]

Expand Down
4 changes: 4 additions & 0 deletions tests/cluster/test_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,6 +8,9 @@

import cratedb_toolkit

pytestmark = pytest.mark.python


ROOT = Path(__file__).parent.parent.parent


Expand Down Expand Up @@ -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):
"""
Expand Down
48 changes: 48 additions & 0 deletions tests/cluster/test_examples_shell.py
Original file line number Diff line number Diff line change
@@ -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
"""

0 comments on commit 8ca895a

Please sign in to comment.