Instead of defining the CliRunner value in each test, we use a fixture. The CliRunner is also configured with stdout and stderr separated because mixing them will pose problem if we use stderr for other purposes in tests, e.g. to emit log messages from a forth-coming HTTP server.
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from click.testing import CliRunner
|
|
|
|
from check_patroni.cli import main
|
|
|
|
|
|
def test_node_patroni_version_ok(runner: CliRunner, fake_restapi) -> None:
|
|
fake_restapi("node_patroni_version")
|
|
result = runner.invoke(
|
|
main,
|
|
[
|
|
"-e",
|
|
"https://10.20.199.3:8008",
|
|
"node_patroni_version",
|
|
"--patroni-version",
|
|
"2.0.2",
|
|
],
|
|
)
|
|
assert result.exit_code == 0
|
|
assert (
|
|
result.stdout
|
|
== "NODEPATRONIVERSION OK - Patroni's version is 2.0.2. | is_version_ok=1;;@0\n"
|
|
)
|
|
|
|
|
|
def test_node_patroni_version_ko(runner: CliRunner, fake_restapi) -> None:
|
|
fake_restapi("node_patroni_version")
|
|
result = runner.invoke(
|
|
main,
|
|
[
|
|
"-e",
|
|
"https://10.20.199.3:8008",
|
|
"node_patroni_version",
|
|
"--patroni-version",
|
|
"1.0.0",
|
|
],
|
|
)
|
|
assert result.exit_code == 2
|
|
assert (
|
|
result.stdout
|
|
== "NODEPATRONIVERSION CRITICAL - Patroni's version is not 1.0.0. | is_version_ok=0;;@0\n"
|
|
)
|