Skip to content

Commit

Permalink
fix: Resolve issue with formatting on nested fields in JSON mode (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai authored Sep 20, 2023
1 parent 21380ce commit 32fd489
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions linodecli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ def _select_json_elements(keys, json_res):
elif isinstance(v, list):
results = []
for elem in v:
if not isinstance(elem, dict):
continue

selected = OutputHandler._select_json_elements(keys, elem)
if not selected:
continue
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/firewalls/test_firewalls_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,43 @@ def test_list_rules_json(create_firewall):
assert result[0]["inbound"][0]["action"] == "ACCEPT"
assert result[0]["inbound"][0]["label"] == "rules-list-test"
assert result[0]["inbound"][0]["addresses"]["ipv4"] == ["198.0.0.1/32"]


def test_list_rules_json_format(create_firewall):
firewall_id = create_firewall
new_label = '"rules-list-test"'
inbound_rule = (
'[{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["198.0.0.1/32"]}, "action": "ACCEPT", "label": '
+ new_label
+ "}]"
)
# adding a rule
exec_test_command(
BASE_CMD
+ [
firewall_id,
"--inbound",
inbound_rule,
"--text",
"--no-headers",
"--delimiter",
",",
]
).stdout.decode().rstrip()
result = json.loads(
exec_test_command(
[
"linode-cli",
"firewalls",
"rules-list",
firewall_id,
"--json",
"--format",
"label",
]
)
.stdout.decode()
.rstrip()
)

assert result[0]["inbound"][0] == {"label": "rules-list-test"}

0 comments on commit 32fd489

Please sign in to comment.