diff --git a/check_patroni/types.py b/check_patroni/types.py index 756792c..258b487 100644 --- a/check_patroni/types.py +++ b/check_patroni/types.py @@ -60,14 +60,16 @@ def rest_api(self: "PatroniResource", service: str) -> Any: _log.debug(e) continue # The status code is already displayed by urllib3 - _log.debug("api call data: %(data)s", {"data": r.text}) + _log.debug( + "api call data: %(data)s", {"data": r.text if r.text else ""} + ) if r.status_code != 200: raise APIError( f"Failed to connect to {endpoint}/{service} status code {r.status_code}" ) - return r.json() + return r.json() if r.text else None raise nagiosplugin.CheckError("Connection failed for all provided endpoints") diff --git a/tests/json/node_is_alive.json b/tests/json/node_is_alive.json deleted file mode 100644 index b697269..0000000 --- a/tests/json/node_is_alive.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "state": "running", - "postmaster_start_time": "2021-08-11 07:57:51.693 UTC", - "role": "replica", - "server_version": 110012, - "cluster_unlocked": false, - "xlog": { - "received_location": 1174407088, - "replayed_location": 1174407088, - "replayed_timestamp": null, - "paused": false - }, - "timeline": 58, - "database_system_identifier": "6965971025273547206", - "patroni": { - "version": "2.0.2", - "scope": "patroni-demo" - } -} diff --git a/tests/test_node_is_alive.py b/tests/test_node_is_alive.py index 40ac391..b840bcd 100644 --- a/tests/test_node_is_alive.py +++ b/tests/test_node_is_alive.py @@ -9,7 +9,7 @@ def test_node_is_alive_ok(mocker: MockerFixture) -> None: runner = CliRunner() - my_mock(mocker, "node_is_alive", 200) + my_mock(mocker, None, 200) result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"]) assert result.exit_code == 0 @@ -17,6 +17,6 @@ def test_node_is_alive_ok(mocker: MockerFixture) -> None: def test_node_is_alive_ko(mocker: MockerFixture) -> None: runner = CliRunner() - my_mock(mocker, "node_is_alive", 404) + my_mock(mocker, None, 404) result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"]) assert result.exit_code == 2 diff --git a/tests/tools.py b/tests/tools.py index fc8a300..cddf540 100644 --- a/tests/tools.py +++ b/tests/tools.py @@ -22,7 +22,7 @@ def my_mock(mocker: MockerFixture, json_file: str, status: int) -> None: def mock_rest_api(self: PatroniResource, service: str) -> Any: if status != 200: raise APIError("Test en erreur pour status code 200") - return getjson(json_file) + return getjson(json_file) if json_file else None mocker.resetall() mocker.patch("check_patroni.types.PatroniResource.rest_api", mock_rest_api)