Get the static items tested.
This commit is contained in:
parent
0d7d8dda08
commit
096e830281
7
keepalived/templates/config.jinja
Normal file
7
keepalived/templates/config.jinja
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{% macro keepalived_config(data) %}
|
||||||
|
{% if data is none %}
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
{{ data }}
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
2
keepalived/templates/test_config.jinja
Normal file
2
keepalived/templates/test_config.jinja
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{% import 'config.jinja' as config %}
|
||||||
|
{{ config.keepalived_config(testdata) }}
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
41
test/test_keepalived_config.py
Executable file
41
test/test_keepalived_config.py
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import os, unittest
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
class TestKeepalivedConfiguration(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.t_dir = os.path.abspath(os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
os.pardir,
|
||||||
|
'keepalived',
|
||||||
|
'templates'))
|
||||||
|
self.t_conf = Environment(loader=FileSystemLoader(self.t_dir),
|
||||||
|
trim_blocks=True)
|
||||||
|
|
||||||
|
def _render(self, data):
|
||||||
|
holder = self.t_conf.get_template('test_config.jinja').render(testdata=data)
|
||||||
|
print(repr(holder))
|
||||||
|
return holder
|
||||||
|
|
||||||
|
def test_string(self):
|
||||||
|
testdata = 'stuff'
|
||||||
|
result = 'stuff\n'
|
||||||
|
self.assertEqual(self._render(testdata), result,
|
||||||
|
'A string should be returned with a line feed.')
|
||||||
|
|
||||||
|
def test_number(self):
|
||||||
|
testdata = 3
|
||||||
|
result = '3\n'
|
||||||
|
self.assertEqual(self._render(testdata), result,
|
||||||
|
'A number should be returned with a line feed.')
|
||||||
|
|
||||||
|
def test_null(self):
|
||||||
|
testdata = None
|
||||||
|
result = '\n'
|
||||||
|
self.assertEqual(self._render(testdata), result,
|
||||||
|
'A null should just return a line feed.')
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user