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

pull/9672/head
Alexei Znamensky 2025-02-02 02:17:58 +13:00 committed by GitHub
parent 439da9e6da
commit c0f57b5c62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 7 deletions

View File

@ -72,7 +72,13 @@ class Helper(object):
"""
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)

View File

@ -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]
@ -54,11 +61,6 @@ test_cases:
out: ''
err: >
No default applications for “x-scheme-handler/http”
- command: [/testbin/gio, mime, x-scheme-handler/http, google-chrome.desktop]
environ: *env-def
rc: 0
out: "Set google-chrome.desktop as the default for x-scheme-handler/http\n"
err: ''
- id: test_set_handler_idempot
input:
handler: google-chrome.desktop
@ -89,3 +91,35 @@ test_cases:
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]
environ: *env-def
rc: 0
out: "2.80.0\n"
err: ''
- 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: ''