2022-02-07 15:11:05 +01:00
|
|
|
from click.testing import CliRunner
|
2023-03-20 11:44:19 +01:00
|
|
|
from pytest_mock import MockerFixture
|
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
|
|
|
|
|
|
|
from .tools import my_mock
|
2021-08-11 19:09:14 +02:00
|
|
|
|
|
|
|
|
2023-08-22 11:08:38 +02:00
|
|
|
def test_node_is_pending_restart_ok(
|
|
|
|
mocker: MockerFixture, use_old_replica_state: bool
|
|
|
|
) -> None:
|
2021-08-11 19:09:14 +02:00
|
|
|
runner = CliRunner()
|
|
|
|
|
|
|
|
my_mock(mocker, "node_is_pending_restart_ok", 200)
|
|
|
|
result = runner.invoke(
|
|
|
|
main, ["-e", "https://10.20.199.3:8008", "node_is_pending_restart"]
|
|
|
|
)
|
|
|
|
assert result.exit_code == 0
|
2023-08-22 11:08:38 +02:00
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "NODEISPENDINGRESTART OK - This node doesn't have the pending restart flag. | is_pending_restart=0;;0\n"
|
|
|
|
)
|
2021-08-11 19:09:14 +02:00
|
|
|
|
|
|
|
|
2023-08-22 11:08:38 +02:00
|
|
|
def test_node_is_pending_restart_ko(
|
|
|
|
mocker: MockerFixture, use_old_replica_state: bool
|
|
|
|
) -> None:
|
2021-08-11 19:09:14 +02:00
|
|
|
runner = CliRunner()
|
|
|
|
|
2023-03-12 19:57:52 +01:00
|
|
|
my_mock(mocker, "node_is_pending_restart_ko", 200)
|
2021-08-11 19:09:14 +02:00
|
|
|
result = runner.invoke(
|
|
|
|
main, ["-e", "https://10.20.199.3:8008", "node_is_pending_restart"]
|
|
|
|
)
|
|
|
|
assert result.exit_code == 2
|
2023-08-22 11:08:38 +02:00
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "NODEISPENDINGRESTART CRITICAL - This node has the pending restart flag. | is_pending_restart=1;;0\n"
|
|
|
|
)
|