test for file.apply_template_on_contents

This commit is contained in:
Christophe Drevet-Droguet 2016-03-11 09:09:36 +01:00
parent 10d882296d
commit dcd6f5a5a9

View file

@ -25,7 +25,12 @@ filemod.__salt__ = {
'cmd.run': cmdmod.run,
'cmd.run_all': cmdmod.run_all
}
filemod.__opts__ = {'test': False}
filemod.__opts__ = {
'test': False,
'file_roots': {'base': 'tmp'},
'pillar_roots': {'base': 'tmp'},
'cachedir': 'tmp',
}
SED_CONTENT = """test
some
@ -34,6 +39,9 @@ content
here
"""
filemod.__grains__ = {}
filemod.__pillar__ = {}
class FileReplaceTestCase(TestCase):
MULTILINE_STRING = textwrap.dedent('''\
@ -516,6 +524,20 @@ class FileModuleTestCase(TestCase):
ret = filemod.group_to_gid(group)
self.assertEqual(ret, group)
def test_apply_template_on_contents(self):
'''
Tests that the templating engine works on string contents
'''
contents = 'This is a {{ template }}.'
defaults = {'template': 'templated file'}
ret = filemod.apply_template_on_contents(
contents,
template='jinja',
context={'opts': filemod.__opts__},
defaults=defaults,
saltenv='base')
self.assertEqual(ret, 'This is a templated file.')
if __name__ == '__main__':
from integration import run_tests