From 7d0fd2fa36d388b0820dab50ae3f84d6f5898594 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Wed, 5 Nov 2025 13:52:10 +0100 Subject: [PATCH 1/2] Add tests for cli commands: monitor token-get, alerts help, alerts definition-view --- tests/integration/helpers.py | 7 ++++ tests/integration/monitor/test_alerts.py | 39 +++++++++++++++++++++++ tests/integration/monitor/test_metrics.py | 32 +++++++++++++++---- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index c58aad09f..35a8a22fe 100644 --- a/tests/integration/helpers.py +++ b/tests/integration/helpers.py @@ -1,5 +1,6 @@ import json import random +import re import subprocess import time from string import ascii_lowercase @@ -204,3 +205,9 @@ def get_random_region_with_caps( matching_region_ids = [region["id"] for region in matching_regions] return random.choice(matching_region_ids) if matching_region_ids else None + + +def assert_help_actions_list(expected_actions, help_output): + output_actions = re.findall("\│\s(\S+)\s*\│", help_output) + for expected_action in expected_actions: + assert expected_action in output_actions diff --git a/tests/integration/monitor/test_alerts.py b/tests/integration/monitor/test_alerts.py index d03471bde..78841feb3 100644 --- a/tests/integration/monitor/test_alerts.py +++ b/tests/integration/monitor/test_alerts.py @@ -3,6 +3,7 @@ from tests.integration.helpers import ( BASE_CMDS, assert_headers_in_lines, + assert_help_actions_list, delete_target_id, exec_test_command, get_random_text, @@ -10,6 +11,27 @@ ) +def test_help_alerts(): + output = exec_test_command( + BASE_CMDS["alerts"] + + [ + "--help", + "--text", + "--delimiter=,", + ] + ) + + actions = [ + "channels-list", + "definition-create", + "definition-delete", + "definition-update", + "definition-view", + "definitions-list-all", + ] + assert_help_actions_list(actions, output) + + def test_channels_list(): res = exec_test_command( BASE_CMDS["alerts"] + ["channels-list", "--text", "--delimiter=,"] @@ -77,6 +99,23 @@ def test_alerts_definition_create(get_channel_id, get_service_type): ) +@pytest.mark.skip +def test_list_alert_definitions_for_service_type(get_service_type): + service_type = get_service_type + output = exec_test_command( + BASE_CMDS["alerts"] + + [ + "definition-view", + service_type, + "--text", + "--delimiter=,", + ] + ) + + headers = ["class", "created", "label", "severity", "service_type"] + assert_headers_in_lines(headers, output.splitlines()) + + def test_alerts_list(): res = exec_test_command( BASE_CMDS["alerts"] diff --git a/tests/integration/monitor/test_metrics.py b/tests/integration/monitor/test_metrics.py index 38742e18e..ae19732da 100644 --- a/tests/integration/monitor/test_metrics.py +++ b/tests/integration/monitor/test_metrics.py @@ -1,8 +1,10 @@ import pytest +from linodecli.exit_codes import ExitCodes from tests.integration.helpers import ( BASE_CMDS, assert_headers_in_lines, + exec_failing_test_command, exec_test_command, ) @@ -62,12 +64,12 @@ def test_service_list(): def test_service_view(get_service_type): - dashboard_id = get_service_type + service_type = get_service_type res = exec_test_command( BASE_CMDS["monitor"] + [ "service-view", - dashboard_id, + service_type, "--text", "--delimiter=,", ] @@ -79,12 +81,12 @@ def test_service_view(get_service_type): def test_dashboard_service_type_list(get_service_type): - dashboard_id = get_service_type + service_type = get_service_type res = exec_test_command( BASE_CMDS["monitor"] + [ "dashboards-list", - dashboard_id, + service_type, "--text", "--delimiter=,", ] @@ -96,12 +98,12 @@ def test_dashboard_service_type_list(get_service_type): def test_metrics_list(get_service_type): - dashboard_id = get_service_type + service_type = get_service_type res = exec_test_command( BASE_CMDS["monitor"] + [ "metrics-list", - dashboard_id, + service_type, "--text", "--delimiter=,", ] @@ -117,3 +119,21 @@ def test_metrics_list(get_service_type): "scrape_interval", ] assert_headers_in_lines(headers, lines) + + +def test_try_create_token_with_not_existing_entity(get_service_type): + service_type = get_service_type + output = exec_failing_test_command( + BASE_CMDS["monitor"] + + [ + "token-get", + service_type, + "--entity_ids", + "99999999999", + "--text", + "--delimiter=,", + ], + expected_code=ExitCodes.REQUEST_FAILED, + ) + assert "Request failed: 403" in output + assert "The following entity_ids are not valid - [99999999999]" in output From 5ae00f7c75441721b12da56bbe81dccd28ddb624 Mon Sep 17 00:00:00 2001 From: Pawel Snoch Date: Fri, 7 Nov 2025 22:53:00 +0100 Subject: [PATCH 2/2] Update service-definition-view action after code fix --- tests/integration/monitor/test_alerts.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/monitor/test_alerts.py b/tests/integration/monitor/test_alerts.py index 78841feb3..d844f698f 100644 --- a/tests/integration/monitor/test_alerts.py +++ b/tests/integration/monitor/test_alerts.py @@ -99,13 +99,12 @@ def test_alerts_definition_create(get_channel_id, get_service_type): ) -@pytest.mark.skip def test_list_alert_definitions_for_service_type(get_service_type): service_type = get_service_type output = exec_test_command( BASE_CMDS["alerts"] + [ - "definition-view", + "service-definition-view", service_type, "--text", "--delimiter=,",