Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test helper: add support for check and diff modes #9666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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