Skip to content

Commit

Permalink
test helper: add support for check and diff modes
Browse files Browse the repository at this point in the history
  • Loading branch information
russoz committed Feb 1, 2025
1 parent 439da9e commit ecd599d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
8 changes: 7 additions & 1 deletion tests/unit/plugins/modules/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ def _test_module(mocker, capfd, patch_ansible_module, test_case):
"""
Run unit tests for each test case in self.test_cases
"""
patch_ansible_module(test_case.input)
args = {}
args.update(test_case.input)
if test_case.flags.get("check"):
args["_ansible_check_mode"] = test_case.flags.get("check")
if test_case.flags.get("diff"):
args["_ansible_diff"] = test_case.flags.get("diff")
patch_ansible_module(args)
self.runner.run(mocker, capfd, test_case)

self.add_func_to_test_module("test_module", _test_module)
Expand Down
42 changes: 38 additions & 4 deletions tests/unit/plugins/modules/test_gio_mime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ test_cases:
output:
handler: google-chrome.desktop
changed: true
stdout: Module executed in check mode
diff:
before:
handler: null
after:
handler: google-chrome.desktop
flags:
skip: test helper does not support check mode yet
check: true
diff: true
mocks:
run_command:
- command: [/testbin/gio, --version]
Expand All @@ -54,18 +61,45 @@ test_cases:
out: ''
err: >
No default applications for “x-scheme-handler/http”
- command: [/testbin/gio, mime, x-scheme-handler/http, google-chrome.desktop]
- id: test_set_handler_idempot
input:
handler: google-chrome.desktop
mime_type: x-scheme-handler/http
output:
handler: google-chrome.desktop
changed: false
mocks:
run_command:
- command: [/testbin/gio, --version]
environ: *env-def
rc: 0
out: "Set google-chrome.desktop as the default for x-scheme-handler/http\n"
out: "2.80.0\n"
err: ''
- id: test_set_handler_idempot
- command: [/testbin/gio, mime, x-scheme-handler/http]
environ: *env-def
rc: 0
out: |
Default application for “x-scheme-handler/https”: google-chrome.desktop
Registered applications:
brave-browser.desktop
firefox.desktop
google-chrome.desktop
firefox_firefox.desktop
Recommended applications:
brave-browser.desktop
firefox.desktop
google-chrome.desktop
firefox_firefox.desktop
err: ''
- id: test_set_handler_idempot_check
input:
handler: google-chrome.desktop
mime_type: x-scheme-handler/http
output:
handler: google-chrome.desktop
changed: false
flags:
check: true
mocks:
run_command:
- command: [/testbin/gio, --version]
Expand Down

0 comments on commit ecd599d

Please sign in to comment.