Skip to content

Commit 062ee9b

Browse files
committed
Cloud API: Improve testing
1 parent 49cfac4 commit 062ee9b

File tree

4 files changed

+57
-39
lines changed

4 files changed

+57
-39
lines changed

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ markers = [
196196
"examples",
197197
"influxdb",
198198
"mongodb",
199+
"python",
200+
"shell",
199201
"slow",
200202
]
201203

tests/cluster/test_examples.sh

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ test_cloud_cluster() {
99
source examples/shell/cloud_cluster.sh
1010
}
1111

12+
test_cloud_import() {
13+
source examples/shell/cloud_import.sh
14+
}
15+
1216
# Load shUnit2.
1317
HERE="$(dirname "$(realpath "$0")")"
1418
. ${HERE}/../util/shunit2

tests/cluster/test_examples.py tests/cluster/test_examples_python.py

+3-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) 2023, Crate.io Inc.
22
# Distributed under the terms of the AGPLv3 license, see LICENSE.
3-
import subprocess
43
from pathlib import Path
54

65
import pytest
@@ -9,6 +8,9 @@
98

109
import cratedb_toolkit
1110

11+
pytestmark = pytest.mark.python
12+
13+
1214
ROOT = Path(__file__).parent.parent.parent
1315

1416

@@ -36,44 +38,6 @@ def test_example_cloud_cluster_exists_python(mocker, mock_cloud_cluster_exists):
3638
main()
3739

3840

39-
def test_example_cloud_cluster_exists_shell(mocker, mock_cloud_cluster_exists, capfd):
40-
"""
41-
Verify that the program `examples/shell/cloud_cluster.sh` works.
42-
In this case, the `ctk` command is mocked completely, so this is nothing serious.
43-
"""
44-
45-
cratedb_toolkit.configure(
46-
settings_accept_env=True,
47-
)
48-
49-
mocker.patch.dict(
50-
"os.environ",
51-
{
52-
"CRATEDB_CLOUD_SUBSCRIPTION_ID": "f33a2f55-17d1-4f21-8130-b6595d7c52db",
53-
"CRATEDB_CLOUD_CLUSTER_NAME": "testcluster",
54-
"CRATEDB_USERNAME": "crate",
55-
},
56-
)
57-
58-
script = ROOT / "tests" / "cluster" / "test_examples.sh"
59-
subprocess.check_call(["bash", script]) # noqa: S603, S607
60-
61-
out, err = capfd.readouterr()
62-
63-
assert "cluster start" in out
64-
assert "shell --command" in out
65-
66-
"""
67-
assert "Mont Blanc massif" in out
68-
assert "Monte Rosa Alps" in out
69-
assert "Deploying/starting/resuming CrateDB Cloud Cluster: id=None, name=plotz" in err
70-
assert "Cluster information: name=plotz, url=https://plotz.aks1.westeurope.azure.cratedb.net:4200" in err
71-
assert "Successfully acquired cluster" in err
72-
assert "CONNECT OK" in err
73-
assert "SELECT 2 rows in set (0.000 sec)" in err
74-
"""
75-
76-
7741
@responses.activate
7842
def test_example_cloud_cluster_with_deploy(mocker, mock_cloud_cluster_deploy):
7943
"""

tests/cluster/test_examples_shell.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
import cratedb_toolkit
7+
8+
ROOT = Path(__file__).parent.parent.parent
9+
10+
pytestmark = pytest.mark.shell
11+
12+
13+
def test_example_cloud_cluster_exists_shell(mocker, mock_cloud_cluster_exists, capfd):
14+
"""
15+
Verify that the program `examples/shell/cloud_cluster.sh` works.
16+
In this case, the `ctk` command is mocked completely, so this is nothing serious.
17+
"""
18+
19+
cratedb_toolkit.configure(
20+
settings_accept_env=True,
21+
)
22+
23+
mocker.patch.dict(
24+
"os.environ",
25+
{
26+
"CRATEDB_CLOUD_SUBSCRIPTION_ID": "f33a2f55-17d1-4f21-8130-b6595d7c52db",
27+
"CRATEDB_CLOUD_CLUSTER_NAME": "testcluster",
28+
"CRATEDB_USERNAME": "crate",
29+
},
30+
)
31+
32+
script = ROOT / "tests" / "cluster" / "test_examples.sh"
33+
subprocess.check_call(["bash", script]) # noqa: S603, S607
34+
35+
out, err = capfd.readouterr()
36+
37+
assert "cluster start" in out
38+
assert "shell --command" in out
39+
40+
"""
41+
assert "Mont Blanc massif" in out
42+
assert "Monte Rosa Alps" in out
43+
assert "Deploying/starting/resuming CrateDB Cloud Cluster: id=None, name=plotz" in err
44+
assert "Cluster information: name=plotz, url=https://plotz.aks1.westeurope.azure.cratedb.net:4200" in err
45+
assert "Successfully acquired cluster" in err
46+
assert "CONNECT OK" in err
47+
assert "SELECT 2 rows in set (0.000 sec)" in err
48+
"""

0 commit comments

Comments
 (0)