From 096e83028145582bc9296e31f859058887faa9d6 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 18 Jan 2017 19:11:23 -0500 Subject: [PATCH] Get the static items tested. --- keepalived/templates/config.jinja | 7 +++++ keepalived/templates/test_config.jinja | 2 ++ test/__init__.py | 0 test/test_keepalived_config.py | 41 ++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 keepalived/templates/config.jinja create mode 100644 keepalived/templates/test_config.jinja create mode 100644 test/__init__.py create mode 100755 test/test_keepalived_config.py 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()