2022-02-07 15:11:05 +01:00
|
|
|
from click.testing import CliRunner
|
2021-08-11 19:09:14 +02:00
|
|
|
|
2022-02-07 15:11:05 +01:00
|
|
|
from check_patroni.cli import main
|
2023-03-20 11:44:19 +01:00
|
|
|
|
2021-08-11 19:09:14 +02:00
|
|
|
|
2023-09-28 10:57:24 +02:00
|
|
|
def test_node_is_primary_ok(fake_restapi) -> None:
|
2021-08-11 19:09:14 +02:00
|
|
|
runner = CliRunner()
|
|
|
|
|
2023-09-28 10:57:24 +02:00
|
|
|
fake_restapi("node_is_primary_ok")
|
2021-08-11 19:09:14 +02:00
|
|
|
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_primary"])
|
|
|
|
assert result.exit_code == 0
|
2023-08-22 11:08:38 +02:00
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "NODEISPRIMARY OK - This node is the primary with the leader lock. | is_primary=1;;@0\n"
|
|
|
|
)
|
2021-08-11 19:09:14 +02:00
|
|
|
|
|
|
|
|
2023-09-28 10:57:24 +02:00
|
|
|
def test_node_is_primary_ko(fake_restapi) -> None:
|
2021-08-11 19:09:14 +02:00
|
|
|
runner = CliRunner()
|
|
|
|
|
2023-09-28 10:57:24 +02:00
|
|
|
fake_restapi("node_is_primary_ko", status=503)
|
2021-08-11 19:09:14 +02:00
|
|
|
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_primary"])
|
|
|
|
assert result.exit_code == 2
|
2023-08-22 11:08:38 +02:00
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "NODEISPRIMARY CRITICAL - This node is not the primary with the leader lock. | is_primary=0;;@0\n"
|
|
|
|
)
|