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.3 KiB
Python
42 lines
1.3 KiB
Python
from click.testing import CliRunner
|
|
|
|
from check_patroni.cli import main
|
|
|
|
|
|
def test_cluster_is_in_maintenance_ok(runner: CliRunner, fake_restapi) -> None:
|
|
fake_restapi("cluster_is_in_maintenance_ok")
|
|
result = runner.invoke(
|
|
main, ["-e", "https://10.20.199.3:8008", "cluster_is_in_maintenance"]
|
|
)
|
|
assert result.exit_code == 0
|
|
assert (
|
|
result.stdout
|
|
== "CLUSTERISINMAINTENANCE OK - is_in_maintenance is 0 | is_in_maintenance=0;;0\n"
|
|
)
|
|
|
|
|
|
def test_cluster_is_in_maintenance_ko(runner: CliRunner, fake_restapi) -> None:
|
|
fake_restapi("cluster_is_in_maintenance_ko")
|
|
result = runner.invoke(
|
|
main, ["-e", "https://10.20.199.3:8008", "cluster_is_in_maintenance"]
|
|
)
|
|
assert result.exit_code == 2
|
|
assert (
|
|
result.stdout
|
|
== "CLUSTERISINMAINTENANCE CRITICAL - is_in_maintenance is 1 (outside range 0:0) | is_in_maintenance=1;;0\n"
|
|
)
|
|
|
|
|
|
def test_cluster_is_in_maintenance_ok_pause_false(
|
|
runner: CliRunner, fake_restapi
|
|
) -> None:
|
|
fake_restapi("cluster_is_in_maintenance_ok_pause_false")
|
|
result = runner.invoke(
|
|
main, ["-e", "https://10.20.199.3:8008", "cluster_is_in_maintenance"]
|
|
)
|
|
assert result.exit_code == 0
|
|
assert (
|
|
result.stdout
|
|
== "CLUSTERISINMAINTENANCE OK - is_in_maintenance is 0 | is_in_maintenance=0;;0\n"
|
|
)
|