Refactored the testing scripts.
This commit is contained in:
parent
096e830281
commit
ff6fc02595
@ -1,7 +1,11 @@
|
|||||||
{% macro keepalived_config(data) %}
|
{%- macro keepalived_config(data) -%}
|
||||||
{% if data is none %}
|
{%- if data is none -%}
|
||||||
|
{{ '\n' }}
|
||||||
{% else %}
|
{%- elif data is mapping -%}
|
||||||
{{ data }}
|
{%- for key, value in data.iteritems() -%}
|
||||||
{% endif %}
|
{{ key }} {{ keepalived_config(value) }}
|
||||||
{% endmacro %}
|
{%- endfor -%}
|
||||||
|
{%- else -%}
|
||||||
|
{{ data }}{{ '\n' }}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endmacro -%}
|
||||||
|
@ -14,28 +14,30 @@ class TestKeepalivedConfiguration(unittest.TestCase):
|
|||||||
self.t_conf = Environment(loader=FileSystemLoader(self.t_dir),
|
self.t_conf = Environment(loader=FileSystemLoader(self.t_dir),
|
||||||
trim_blocks=True)
|
trim_blocks=True)
|
||||||
|
|
||||||
def _render(self, data):
|
def renderTest(self, data, result):
|
||||||
holder = self.t_conf.get_template('test_config.jinja').render(testdata=data)
|
holder = self.t_conf.get_template('test_config.jinja').render(testdata=data)
|
||||||
print(repr(holder))
|
output = repr(holder) + ' did not equal ' + repr(result)
|
||||||
return holder
|
self.assertEqual(holder, result, output)
|
||||||
|
|
||||||
def test_string(self):
|
def test_string(self):
|
||||||
testdata = 'stuff'
|
testdata = 'stuff'
|
||||||
result = 'stuff\n'
|
result = 'stuff\n'
|
||||||
self.assertEqual(self._render(testdata), result,
|
self.renderTest(testdata, result)
|
||||||
'A string should be returned with a line feed.')
|
|
||||||
|
|
||||||
def test_number(self):
|
def test_number(self):
|
||||||
testdata = 3
|
testdata = 3
|
||||||
result = '3\n'
|
result = '3\n'
|
||||||
self.assertEqual(self._render(testdata), result,
|
self.renderTest(testdata, result)
|
||||||
'A number should be returned with a line feed.')
|
|
||||||
|
|
||||||
def test_null(self):
|
def test_null(self):
|
||||||
testdata = None
|
testdata = None
|
||||||
result = '\n'
|
result = '\n'
|
||||||
self.assertEqual(self._render(testdata), result,
|
self.renderTest(testdata, result)
|
||||||
'A null should just return a line feed.')
|
|
||||||
|
def test_key_value_pair(self):
|
||||||
|
testdata = {'flintstone': 'fred'}
|
||||||
|
result = 'flintstone fred\n'
|
||||||
|
self.renderTest(testdata, result)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user