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