Skip to content

Commit 0b5b673

Browse files
Add tests for cli commands: monitor token-get, alerts help, alerts definition-view
1 parent 1ab118d commit 0b5b673

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

tests/integration/helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import random
3+
import re
34
import subprocess
45
import time
56
from string import ascii_lowercase
@@ -204,3 +205,9 @@ def get_random_region_with_caps(
204205
matching_region_ids = [region["id"] for region in matching_regions]
205206

206207
return random.choice(matching_region_ids) if matching_region_ids else None
208+
209+
210+
def assert_help_actions_list(expected_actions, help_output):
211+
output_actions = re.findall("\│\s(\S+)\s*\│", help_output)
212+
for expected_action in expected_actions:
213+
assert expected_action in output_actions

tests/integration/monitor/test_alerts.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,35 @@
33
from tests.integration.helpers import (
44
BASE_CMDS,
55
assert_headers_in_lines,
6+
assert_help_actions_list,
67
delete_target_id,
78
exec_test_command,
89
get_random_text,
910
retry_exec_test_command_with_delay,
1011
)
1112

1213

14+
def test_help_alerts():
15+
output = exec_test_command(
16+
BASE_CMDS["alerts"]
17+
+ [
18+
"--help",
19+
"--text",
20+
"--delimiter=,",
21+
]
22+
)
23+
24+
actions = [
25+
"channels-list",
26+
"definition-create",
27+
"definition-delete",
28+
"definition-update",
29+
"definition-view",
30+
"definitions-list-all",
31+
]
32+
assert_help_actions_list(actions, output)
33+
34+
1335
def test_channels_list():
1436
res = exec_test_command(
1537
BASE_CMDS["alerts"] + ["channels-list", "--text", "--delimiter=,"]
@@ -77,6 +99,22 @@ def test_alerts_definition_create(get_channel_id, get_service_type):
7799
)
78100

79101

102+
def test_list_alert_definitions_for_service_type(get_service_type):
103+
service_type = get_service_type
104+
output = exec_test_command(
105+
BASE_CMDS["alerts"]
106+
+ [
107+
"service-definition-view",
108+
service_type,
109+
"--text",
110+
"--delimiter=,",
111+
]
112+
)
113+
114+
headers = ["class", "created", "label", "severity", "service_type"]
115+
assert_headers_in_lines(headers, output.splitlines())
116+
117+
80118
def test_alerts_list():
81119
res = exec_test_command(
82120
BASE_CMDS["alerts"]

tests/integration/monitor/test_metrics.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import pytest
22

3+
from linodecli.exit_codes import ExitCodes
34
from tests.integration.helpers import (
45
BASE_CMDS,
56
assert_headers_in_lines,
7+
exec_failing_test_command,
68
exec_test_command,
79
)
810

@@ -62,12 +64,12 @@ def test_service_list():
6264

6365

6466
def test_service_view(get_service_type):
65-
dashboard_id = get_service_type
67+
service_type = get_service_type
6668
res = exec_test_command(
6769
BASE_CMDS["monitor"]
6870
+ [
6971
"service-view",
70-
dashboard_id,
72+
service_type,
7173
"--text",
7274
"--delimiter=,",
7375
]
@@ -79,12 +81,12 @@ def test_service_view(get_service_type):
7981

8082

8183
def test_dashboard_service_type_list(get_service_type):
82-
dashboard_id = get_service_type
84+
service_type = get_service_type
8385
res = exec_test_command(
8486
BASE_CMDS["monitor"]
8587
+ [
8688
"dashboards-list",
87-
dashboard_id,
89+
service_type,
8890
"--text",
8991
"--delimiter=,",
9092
]
@@ -96,12 +98,12 @@ def test_dashboard_service_type_list(get_service_type):
9698

9799

98100
def test_metrics_list(get_service_type):
99-
dashboard_id = get_service_type
101+
service_type = get_service_type
100102
res = exec_test_command(
101103
BASE_CMDS["monitor"]
102104
+ [
103105
"metrics-list",
104-
dashboard_id,
106+
service_type,
105107
"--text",
106108
"--delimiter=,",
107109
]
@@ -117,3 +119,21 @@ def test_metrics_list(get_service_type):
117119
"scrape_interval",
118120
]
119121
assert_headers_in_lines(headers, lines)
122+
123+
124+
def test_try_create_token_with_not_existing_entity(get_service_type):
125+
service_type = get_service_type
126+
output = exec_failing_test_command(
127+
BASE_CMDS["monitor"]
128+
+ [
129+
"token-get",
130+
service_type,
131+
"--entity_ids",
132+
"99999999999",
133+
"--text",
134+
"--delimiter=,",
135+
],
136+
expected_code=ExitCodes.REQUEST_FAILED,
137+
)
138+
assert "Request failed: 403" in output
139+
assert "The following entity_ids are not valid - [99999999999]" in output

0 commit comments

Comments
 (0)