Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Dec 9, 2022
1 parent a1c5cf8 commit b77f03c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions tests/unit/plugins/action/network/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path):

# This doesn't need to be conditional, but doing so tests the equivalent
# `if backup_options:` in the action plugin itself.
backup_options = None
if backup_dir or backup_file:
plugin._task.args["backup_options"] = {
backup_options = {
"dir_path": backup_dir,
"filename": backup_file,
}
Expand All @@ -79,7 +80,7 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path):

try:
# result is updated in place, nothing is returned
plugin._handle_backup_option(result, task_vars)
plugin._handle_backup_option(result, task_vars, backup_options)
assert not result.get("failed")

with open(result["backup_path"]) as backup_file_obj:
Expand Down Expand Up @@ -108,7 +109,7 @@ def test_backup_options(plugin, backup_dir, backup_file, role_path):
if backup_file:
# check for idempotency
result = {"__backup__": content}
plugin._handle_backup_option(result, task_vars)
plugin._handle_backup_option(result, task_vars, backup_options)
assert not result.get("failed")
assert result["changed"] is False

Expand All @@ -123,21 +124,19 @@ def test_backup_no_content(plugin):
with pytest.raises(
AnsibleError, match="Failed while reading configuration backup"
):
plugin._handle_backup_option(result, task_vars)
plugin._handle_backup_option(result, task_vars, backup_options=None)


def test_backup_options_error(plugin):
result = {"__backup__": ""}
task_vars = {}

with tempfile.NamedTemporaryFile() as existing_file:
plugin._task.args = {
"backup_options": {
"dir_path": existing_file.name,
"filename": "backup_file",
}
backup_options = {
"dir_path": existing_file.name,
"filename": "backup_file",
}
plugin._handle_backup_option(result, task_vars)
plugin._handle_backup_option(result, task_vars, backup_options)

assert result["failed"] is True
assert result["msg"] == (
Expand Down

0 comments on commit b77f03c

Please sign in to comment.