diff --git a/tests/integration/helpers.py b/tests/integration/helpers.py index c58aad09..35a8a22f 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 d03471bd..d844f698 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,22 @@ def test_alerts_definition_create(get_channel_id, get_service_type): ) +def test_list_alert_definitions_for_service_type(get_service_type): + service_type = get_service_type + output = exec_test_command( + BASE_CMDS["alerts"] + + [ + "service-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 38742e18..ae19732d 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