2017-01-19 01:11:23 +01:00
|
|
|
#!/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)
|
|
|
|
|
2017-01-19 01:51:16 +01:00
|
|
|
def renderTest(self, data, result):
|
2017-01-19 01:11:23 +01:00
|
|
|
holder = self.t_conf.get_template('test_config.jinja').render(testdata=data)
|
2017-01-19 01:51:16 +01:00
|
|
|
output = repr(holder) + ' did not equal ' + repr(result)
|
|
|
|
self.assertEqual(holder, result, output)
|
2017-01-19 01:11:23 +01:00
|
|
|
|
|
|
|
def test_string(self):
|
|
|
|
testdata = 'stuff'
|
|
|
|
result = 'stuff\n'
|
2017-01-19 01:51:16 +01:00
|
|
|
self.renderTest(testdata, result)
|
2017-01-19 01:11:23 +01:00
|
|
|
|
|
|
|
def test_number(self):
|
|
|
|
testdata = 3
|
|
|
|
result = '3\n'
|
2017-01-19 01:51:16 +01:00
|
|
|
self.renderTest(testdata, result)
|
2017-01-19 01:11:23 +01:00
|
|
|
|
|
|
|
def test_null(self):
|
|
|
|
testdata = None
|
|
|
|
result = '\n'
|
2017-01-19 01:51:16 +01:00
|
|
|
self.renderTest(testdata, result)
|
|
|
|
|
|
|
|
def test_key_value_pair(self):
|
|
|
|
testdata = {'flintstone': 'fred'}
|
|
|
|
result = 'flintstone fred\n'
|
|
|
|
self.renderTest(testdata, result)
|
2017-01-19 01:11:23 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|