Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Dependencies: Permitted installation of click 8.3

## 2026/03/16 v0.0.46
- I/O: API improvements: `ctk {load,save} table` became `ctk {load,save}`
Also, the `--cluster-url` option becomes optional. That's a much more
Expand Down
2 changes: 1 addition & 1 deletion cratedb_toolkit/cfr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def job_statistics(ctx: click.Context):
@click.option(
"--anonymize",
type=str,
is_flag=False,
is_flag=True,
flag_value="decoder_dictionary.json", # Use this value when flag is used without value
default=None, # No anonymization by default
help="Path to the decoder dictionary file for anonymizing SQL statements",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ dependencies = [
"attrs<27",
"boltons<26",
"cattrs<27",
"click<8.2",
"click<8.4",
"click-aliases>=1.0.4,<2",
"colorama<1",
"colorlog",
Expand Down
8 changes: 4 additions & 4 deletions tests/cfr/test_jobstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_cfr_jobstats_collect_self(cratedb, caplog):
args="jobstats collect --once",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify outcome: Log output.
assert "Recording information snapshot" in caplog.messages
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_cfr_jobstats_collect_anonymized(cratedb, caplog):
args="jobstats collect --once --anonymize",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify outcome: Log output.
assert "Recording information snapshot" in caplog.messages
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_cfr_jobstats_collect_reportdb(cratedb, caplog):
args=f"jobstats collect --once --reportdb={dburi_report}",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify outcome: Log output.
assert "Recording information snapshot" in caplog.messages
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_cfr_jobstats_view(cratedb):
args="jobstats view",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify outcome.
info = json.loads(result.output)
Expand Down
56 changes: 31 additions & 25 deletions tests/cfr/test_systable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ruff: noqa: E402
import importlib
import json
import os.path
import re
Expand All @@ -7,6 +8,7 @@
import tarfile

import pytest
from verlib2 import Version

pymongo = pytest.importorskip("polars", reason="Skipping tests because polars is not installed")

Expand All @@ -29,21 +31,31 @@ def filenames(path: Path):
return sorted([item.name for item in path.iterdir()])


def test_cfr_sys_export_success(cratedb, tmp_path, caplog):
@pytest.fixture(scope="session")
def click_kwargs():
"""
Click 8.2 no longer understands `mix_stderr`.
"""
kwargs = {}
click_version = importlib.metadata.version("click")
if Version(click_version) < Version("8.2"):
kwargs = {"mix_stderr": False}
return kwargs


def test_cfr_sys_export_success(cratedb, click_kwargs, tmp_path, caplog):
"""
Verify `ctk cfr sys-export` works.
"""

# Invoke command.
runner = CliRunner(
env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, mix_stderr=False
)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, **click_kwargs)
result = runner.invoke(
cli,
args="--debug sys-export",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify log output.
assert "Exporting system tables to" in caplog.text
Expand All @@ -60,23 +72,21 @@ def test_cfr_sys_export_success(cratedb, tmp_path, caplog):
assert len(data_files) >= 10


def test_cfr_sys_export_to_archive_file(cratedb, tmp_path, caplog):
def test_cfr_sys_export_to_archive_file(cratedb, click_kwargs, tmp_path, caplog):
"""
Verify `ctk cfr sys-export some-file.tgz` works.
"""

target = os.path.join(tmp_path, "cluster-data.tgz")

# Invoke command.
runner = CliRunner(
env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, mix_stderr=False
)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, **click_kwargs)
result = runner.invoke(
cli,
args=f"--debug sys-export {target}",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify log output.
assert "Exporting system tables to" in caplog.text
Expand All @@ -100,35 +110,33 @@ def test_cfr_sys_export_to_archive_file(cratedb, tmp_path, caplog):
assert len(data_files) >= 10


def test_cfr_sys_export_failure(cratedb, tmp_path, caplog):
def test_cfr_sys_export_failure(cratedb, click_kwargs, tmp_path, caplog):
"""
Verify `ctk cfr sys-export` failure.
"""

# Invoke command.
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": "crate://foo.bar/", "CFR_TARGET": str(tmp_path)}, mix_stderr=False)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": "crate://foo.bar/", "CFR_TARGET": str(tmp_path)}, **click_kwargs)
result = runner.invoke(
cli,
args="--debug sys-export",
catch_exceptions=False,
)
assert result.exit_code == 1
assert result.exit_code == 1, result.output

# Verify log output.
assert "Failed to establish a new connection" in caplog.text or "Failed to resolve" in caplog.text
assert result.output == ""


def test_cfr_sys_export_ensure_table_name_is_quoted(cratedb, tmp_path, caplog):
runner = CliRunner(
env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, mix_stderr=False
)
def test_cfr_sys_export_ensure_table_name_is_quoted(cratedb, click_kwargs, tmp_path, caplog):
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_TARGET": str(tmp_path)}, **click_kwargs)
result = runner.invoke(
cli,
args="--debug sys-export",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

path = Path(json.loads(result.stdout)["path"])
sys_cluster_table_schema = path / "schema" / "sys-cluster.sql"
Expand Down Expand Up @@ -178,15 +186,13 @@ def test_cfr_sys_import_success(cratedb, tmp_path, caplog):
shutil.copy(sys_operations_data, data_path)

# Invoke command.
runner = CliRunner(
env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_SOURCE": str(tmp_path)}, mix_stderr=False
)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi, "CFR_SOURCE": str(tmp_path)})
result = runner.invoke(
cli,
args="--debug sys-import",
catch_exceptions=False,
)
assert result.exit_code == 0
assert result.exit_code == 0, result.output

# Verify log output.
assert "Importing system tables from" in caplog.text
Expand All @@ -200,19 +206,19 @@ def test_cfr_sys_import_success(cratedb, tmp_path, caplog):
assert cratedb.database.count_records("sys-operations") == 1


def test_cfr_sys_import_failure(cratedb, tmp_path, caplog):
def test_cfr_sys_import_failure(cratedb, click_kwargs, tmp_path, caplog):
"""
Verify `ctk cfr sys-import` failure.
"""

# Invoke command.
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": "crate://foo.bar/", "CFR_SOURCE": str(tmp_path)}, mix_stderr=False)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": "crate://foo.bar/", "CFR_SOURCE": str(tmp_path)}, **click_kwargs)
result = runner.invoke(
cli,
args="--debug sys-import",
catch_exceptions=False,
)
assert result.exit_code == 1
assert result.exit_code == 1, result.output

# Verify log output.
assert "Failed to establish a new connection" in caplog.text or "Failed to resolve" in caplog.text
Expand Down
4 changes: 2 additions & 2 deletions tests/settings/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_settings_list(cratedb, caplog):
"""

# Invoke command.
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi}, mix_stderr=False)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi})
result = runner.invoke(
cli,
args="list",
Expand All @@ -26,7 +26,7 @@ def test_settings_compare(cratedb, caplog):
"""

# Invoke command.
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi}, mix_stderr=False)
runner = CliRunner(env={"CRATEDB_CLUSTER_URL": cratedb.database.dburi})
result = runner.invoke(
cli,
args="compare --no-color",
Expand Down