mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-04 01:13:00 +00:00
unit tests: use f-strings (#10993)
This commit is contained in:
parent
e177d1e61a
commit
efad7a0d38
25 changed files with 54 additions and 78 deletions
|
|
@ -31,8 +31,7 @@ def test_doas_basic(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -c 'echo %s; %s'""" % (doas_exe, doas_flags, default_exe, success,
|
||||
default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{doas_exe} {doas_flags} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
||||
|
||||
def test_doas(mocker, parser, reset_cli_args):
|
||||
|
|
@ -54,8 +53,7 @@ def test_doas(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s -u %s %s -c 'echo %s; %s'""" % (doas_exe, doas_flags, task['become_user'], default_exe, success,
|
||||
default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{doas_exe} {doas_flags} -u {task['become_user']} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
||||
|
||||
def test_doas_varoptions(mocker, parser, reset_cli_args):
|
||||
|
|
@ -80,5 +78,4 @@ def test_doas_varoptions(mocker, parser, reset_cli_args):
|
|||
}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s -u %s %s -c 'echo %s; %s'""" % (doas_exe, doas_flags, var_options['ansible_become_user'], default_exe, success,
|
||||
default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{doas_exe} {doas_flags} -u {var_options['ansible_become_user']} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ def test_dzdo_basic(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s %s -c 'echo %s; %s'""" % (dzdo_exe, dzdo_flags, default_exe,
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{dzdo_exe} {dzdo_flags} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
||||
|
||||
def test_dzdo(mocker, parser, reset_cli_args):
|
||||
|
|
@ -54,8 +53,7 @@ def test_dzdo(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, dzdo_flags, task['become_user'], default_exe,
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{dzdo_exe} {dzdo_flags} -u {task['become_user']} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
task['become_pass'] = 'testpass'
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
|
|
@ -85,8 +83,7 @@ def test_dzdo_varoptions(mocker, parser, reset_cli_args):
|
|||
}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s -u %s %s -c 'echo %s; %s'""" % (dzdo_exe, dzdo_flags, var_options['ansible_become_user'], default_exe,
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{dzdo_exe} {dzdo_flags} -u {var_options['ansible_become_user']} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
var_options['ansible_become_pass'] = 'testpass'
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ def test_ksu_basic(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -e %s -c 'echo %s; %s'""" % (ksu_exe, task['become_user'], ksu_flags,
|
||||
default_exe, success, default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{ksu_exe} {task['become_user']} {ksu_flags} -e {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
||||
|
||||
def test_ksu(mocker, parser, reset_cli_args):
|
||||
|
|
@ -55,8 +54,7 @@ def test_ksu(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -e %s -c 'echo %s; %s'""" % (ksu_exe, task['become_user'], ksu_flags,
|
||||
default_exe, success, default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{ksu_exe} {task['become_user']} {ksu_flags} -e {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
||||
|
||||
def test_ksu_varoptions(mocker, parser, reset_cli_args):
|
||||
|
|
@ -81,5 +79,4 @@ def test_ksu_varoptions(mocker, parser, reset_cli_args):
|
|||
}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s %s -e %s -c 'echo %s; %s'""" % (ksu_exe, var_options['ansible_become_user'], ksu_flags,
|
||||
default_exe, success, default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{ksu_exe} {var_options['ansible_become_user']} {ksu_flags} -e {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ def test_pbrun_basic(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s 'echo %s; %s'""" % (pbrun_exe, pbrun_flags,
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pbrun_exe} {pbrun_flags} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
||||
|
||||
def test_pbrun(mocker, parser, reset_cli_args):
|
||||
|
|
@ -54,8 +53,7 @@ def test_pbrun(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s -u %s 'echo %s; %s'""" % (pbrun_exe, pbrun_flags, task['become_user'],
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pbrun_exe} {pbrun_flags} -u {task['become_user']} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
||||
|
||||
def test_pbrun_var_varoptions(mocker, parser, reset_cli_args):
|
||||
|
|
@ -80,5 +78,4 @@ def test_pbrun_var_varoptions(mocker, parser, reset_cli_args):
|
|||
}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s -u %s 'echo %s; %s'""" % (pbrun_exe, pbrun_flags, var_options['ansible_become_user'],
|
||||
success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pbrun_exe} {pbrun_flags} -u {var_options['ansible_become_user']} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def test_pfexec_basic(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s 'echo %s; %s'""" % (pfexec_exe, pfexec_flags, success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pfexec_exe} {pfexec_flags} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
||||
|
||||
def test_pfexec(mocker, parser, reset_cli_args):
|
||||
|
|
@ -53,7 +53,7 @@ def test_pfexec(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s 'echo %s; %s'""" % (pfexec_exe, pfexec_flags, success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pfexec_exe} {pfexec_flags} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
||||
|
||||
def test_pfexec_varoptions(mocker, parser, reset_cli_args):
|
||||
|
|
@ -78,4 +78,4 @@ def test_pfexec_varoptions(mocker, parser, reset_cli_args):
|
|||
}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert re.match("""%s %s 'echo %s; %s'""" % (pfexec_exe, pfexec_flags, success, default_cmd), cmd) is not None
|
||||
assert re.match(f"""{pfexec_exe} {pfexec_flags} 'echo {success}; {default_cmd}'""", cmd) is not None
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ def test_sudosu(mocker, parser, reset_cli_args):
|
|||
var_options = {}
|
||||
cmd = call_become_plugin(task, var_options, cmd=default_cmd, executable=default_exe)
|
||||
print(cmd)
|
||||
assert (re.match("""%s %s su -l %s %s -c 'echo %s; %s'""" % (sudo_exe, sudo_flags, task['become_user'],
|
||||
default_exe, success, default_cmd), cmd) is not None)
|
||||
assert (re.match(f"""{sudo_exe} {sudo_flags} su -l {task['become_user']} {default_exe} -c 'echo {success}; {default_cmd}'""", cmd) is not None)
|
||||
|
||||
task = {
|
||||
'become_user': 'foo',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue