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:
Joshua Kehn
2013-10-06 13:43:16 -04:00
parent ea73151757
commit cc0c908cee
2 changed files with 47 additions and 3 deletions

View File

@@ -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)