mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 13:52:54 +00:00
Added validate option to lineinfile
The validate option is constructed similarly to the template command's validate option. TestRunner.py has been updated to include two new tests, one for passing and one for failing validation.
This commit is contained in:
@@ -460,6 +460,32 @@ class TestRunner(unittest.TestCase):
|
||||
idx = artifact.index('communication. Typically it is depicted as a lunch-box sized object with some')
|
||||
assert artifact[idx - 1] == testline
|
||||
|
||||
# Testing validate
|
||||
testline = 'Tenth: Testing with validate'
|
||||
testcase = ('lineinfile', [
|
||||
"dest=%s" % sample,
|
||||
"regexp='^Tenth: '",
|
||||
"line='%s'" % testline,
|
||||
"validate='grep -q Tenth %s'",
|
||||
])
|
||||
result = self._run(*testcase)
|
||||
assert result['changed'], "File wasn't changed when it should have been"
|
||||
assert result['msg'] == 'line added', "msg was incorrect"
|
||||
artifact = [ x.strip() for x in open(sample) ]
|
||||
assert artifact[-1] == testline
|
||||
|
||||
|
||||
# Testing validate
|
||||
testline = '#11: Testing with validate'
|
||||
testcase = ('lineinfile', [
|
||||
"dest=%s" % sample,
|
||||
"regexp='^#11: '",
|
||||
"line='%s'" % testline,
|
||||
"validate='grep -q #12# %s'",
|
||||
])
|
||||
result = self._run(*testcase)
|
||||
assert result['failed']
|
||||
|
||||
# cleanup
|
||||
os.unlink(sample)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user