Refine the integration test code

This commit is contained in:
Victor Krasnov 2023-07-07 15:16:10 +08:00
parent 87ea1b6667
commit 95fedaedff
2 changed files with 2 additions and 64 deletions

View File

@ -1,58 +0,0 @@
import pytest
import logging
from helpers.cluster import ClickHouseCluster
from datetime import datetime
log_dir = "/var/log/clickhouse-server/"
cluster = ClickHouseCluster(__file__)
@pytest.fixture(scope="module")
def started_cluster():
cluster.add_instance(
"file-names-from-config",
main_configs=["configs/config-file-template.xml"],
clickhouse_log_file=None,
clickhouse_error_log_file=None,
)
cluster.add_instance(
"file-names-from-params",
clickhouse_log_file=log_dir + "clickhouse-server-%Y-%m.log",
clickhouse_error_log_file=log_dir + "clickhouse-server-%Y-%m.err.log",
)
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_check_file_names(started_cluster):
now = datetime.now()
log_file = (
log_dir + f"clickhouse-server-{now.strftime('%Y')}-{now.strftime('%m')}.log"
)
err_log_file = (
log_dir + f"clickhouse-server-{now.strftime('%Y')}-{now.strftime('%m')}.err.log"
)
logging.debug(f"log_file {log_file} err_log_file {err_log_file}")
for name, instance in started_cluster.instances.items():
files = instance.exec_in_container(
["bash", "-c", f"ls -lh {log_dir}"], nothrow=True
)
logging.debug(f"check instance '{name}': {log_dir} contains: {files}")
assert (
instance.exec_in_container(["bash", "-c", f"ls {log_file}"], nothrow=True)
== log_file + "\n"
)
assert (
instance.exec_in_container(
["bash", "-c", f"ls {err_log_file}"], nothrow=True
)
== err_log_file + "\n"
)

View File

@ -30,12 +30,8 @@ def started_cluster():
def test_check_file_names(started_cluster):
now = datetime.now()
log_file = (
log_dir + f"clickhouse-server-{now.strftime('%Y')}-{now.strftime('%m')}.log"
)
err_log_file = (
log_dir + f"clickhouse-server-{now.strftime('%Y')}-{now.strftime('%m')}.err.log"
)
log_file = log_dir + f"clickhouse-server-{now.strftime('%Y-%m')}.log"
err_log_file = log_dir + f"clickhouse-server-{now.strftime('%Y-%m')}.err.log"
logging.debug(f"log_file {log_file} err_log_file {err_log_file}")
for name, instance in started_cluster.instances.items():