diff --git a/keepalived/templates/config.jinja b/keepalived/templates/config.jinja new file mode 100644 index 0000000..a8dc487 --- /dev/null +++ b/keepalived/templates/config.jinja @@ -0,0 +1,7 @@ +{% macro keepalived_config(data) %} +{% if data is none %} + +{% else %} +{{ data }} +{% endif %} +{% endmacro %} diff --git a/keepalived/templates/test_config.jinja b/keepalived/templates/test_config.jinja new file mode 100644 index 0000000..baf56b5 --- /dev/null +++ b/keepalived/templates/test_config.jinja @@ -0,0 +1,2 @@ +{% import 'config.jinja' as config %} +{{ config.keepalived_config(testdata) }} diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_keepalived_config.py b/test/test_keepalived_config.py new file mode 100755 index 0000000..696fbcd --- /dev/null +++ b/test/test_keepalived_config.py @@ -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()