-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathtest_cratedb.py
More file actions
88 lines (75 loc) · 3.06 KB
/
test_cratedb.py
File metadata and controls
88 lines (75 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import urllib.parse
import os
import sqlalchemy
import pytest
from testcontainers.cratedb import CrateDBContainer
@pytest.mark.parametrize("version", ["5.9", "5.10", "6.0", "latest"])
def test_docker_run_cratedb_versions(version: str):
with CrateDBContainer(f"crate:{version}") as container:
engine = sqlalchemy.create_engine(container.get_connection_url())
with engine.begin() as conn:
result = conn.execute(sqlalchemy.text("select 1+2+3+4+5"))
sum_result = result.fetchone()[0]
assert sum_result == 15
@pytest.mark.parametrize(
"ports, expected",
[
({5432: None, 4200: None}, False),
({5432: 5432, 4200: 4200}, {5432: 5432, 4200: 4200}),
],
)
def test_docker_run_cratedb_ports(ports, expected):
with CrateDBContainer("crate:latest", ports=ports) as container:
exposed_ports = container.exposed_ports()
assert len(exposed_ports) == 2
assert all(map(lambda port: isinstance(port, int), exposed_ports))
if expected:
assert exposed_ports == expected
def test_docker_run_cratedb_credentials():
expected_user, expected_password, expected_port = "user1", "pass1", 4200
expected_default_dialect, expected_default_host = "crate", "localhost"
expected_defined_dialect, expected_defined_host = "somedialect", "somehost"
os.environ["CRATEDB_USER"], os.environ["CRATEDB_PASSWORD"] = expected_user, expected_password
with CrateDBContainer("crate:latest", ports={4200: expected_port}) as container:
url = urllib.parse.urlparse(container.get_connection_url())
user, password = url.netloc.split("@")[0].split(":")
host, port = url.netloc.split("@")[1].split(":")
assert user == expected_user
assert password == expected_password
assert url.scheme == expected_default_dialect
assert host == expected_default_host
assert int(port) == expected_port
url = urllib.parse.urlparse(
container.get_connection_url(dialect=expected_defined_dialect, host=expected_defined_host)
)
host, _ = url.netloc.split("@")[1].split(":")
assert url.scheme == expected_defined_dialect
assert host == expected_defined_host
@pytest.mark.parametrize(
"opts, expected",
[
pytest.param(
{"indices.breaker.total.limit": "90%"},
(
"-Cdiscovery.type=single-node "
"-Cnode.attr.storage=hot "
"-Cpath.repo=/tmp/snapshots "
"-Cindices.breaker.total.limit=90%"
),
id="add_cmd_option",
),
pytest.param(
{"discovery.type": "zen", "indices.breaker.total.limit": "90%"},
(
"-Cdiscovery.type=zen "
"-Cnode.attr.storage=hot "
"-Cpath.repo=/tmp/snapshots "
"-Cindices.breaker.total.limit=90%"
),
id="override_defaults",
),
],
)
def test_build_command(opts, expected):
db = CrateDBContainer(cmd_opts=opts)
assert db._command == expected