Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Nov 29, 2022
1 parent 142bc08 commit d50c743
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 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 @@ -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 d50c743

Please sign in to comment.