Skip to content

Commit

Permalink
add unit test for action_flags_command
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Nov 26, 2024
1 parent e9d7379 commit cfb1537
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/module_utils/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import yaml


def action_flags_command(command: list[str], flags: set[str] = {}, action_flags_map: dict[str, str] = {}) -> list[str]:
def action_flags_command(command: list[str], flags: set[str] = [], action_flags_map: dict[str, str] = {}) -> list[str]:
"""convert action flags dict into list of command strings"""
# in this function command list is mutable pseudo-reference and also returned

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/plugins/module_utils/test_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ def test_validate_json_yaml_file():
assert not universal.validate_json_yaml_file('.gitignore')


def test_action_flags_command():
"""test action flags dict to list of command strings converter"""
# test accurate flags conversion
assert universal.action_flags_command(['hello'], ['foo', 'bar'], {'foo': '--foo', 'bar': '--bar'}) == ['hello', '--foo', '--bar']

# test unsupported flag input
with pytest.warns(RuntimeWarning, match='Unsupported flag specified: baz'):
assert universal.action_flags_command(['hello'], ['foo', 'baz'], {'foo': '--foo', 'bar': '--bar'}) == ['hello', '--foo']

# test action with no action flags input
with pytest.warns(RuntimeWarning, match='Unsupported flag specified: foo'):
assert universal.action_flags_command(['hello'], ['foo'], {}) == ['hello']


def test_vars_converter():
"""test ansible vars param to hashi cli converter"""
# test accurate vars conversion
Expand Down

0 comments on commit cfb1537

Please sign in to comment.