-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
ctk shell
to also talk to CrateDB standalone databases
- Loading branch information
Showing
3 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import json | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from cratedb_toolkit.shell.cli import cli | ||
from tests.conftest import TESTDRIVE_DATA_SCHEMA | ||
|
||
|
||
def test_shell_success(cratedb): | ||
""" | ||
Verify successful incantation of `ctk shell`. | ||
""" | ||
runner = CliRunner() | ||
|
||
database_url = cratedb.get_connection_url() + "?schema=" + TESTDRIVE_DATA_SCHEMA | ||
|
||
result = runner.invoke( | ||
cli, | ||
args=f"--cratedb-sqlalchemy-url='{database_url}' --command 'SELECT 42 AS answer;' --format=json", | ||
catch_exceptions=False, | ||
) | ||
assert result.exit_code == 0 | ||
assert json.loads(result.output) == [{"answer": 42}] | ||
|
||
|
||
def test_shell_failure_no_address(): | ||
""" | ||
Verify `ctk shell` fails when invoked without database address. | ||
""" | ||
runner = CliRunner() | ||
|
||
with pytest.raises(ValueError) as ex: | ||
runner.invoke( | ||
cli, | ||
args="--command 'SELECT 42 AS answer;' --format=json", | ||
catch_exceptions=False, | ||
) | ||
assert ex.match("Unknown database address") |