test base and systemd templating
This commit is contained in:
parent
2d8ef64904
commit
3c5d4a4fa6
25 changed files with 34 additions and 9 deletions
0
tests/dictionaries/01base_file_owner/no_base
Normal file
0
tests/dictionaries/01base_file_owner/no_base
Normal file
0
tests/dictionaries/01base_file_owner_variable/no_base
Normal file
0
tests/dictionaries/01base_file_owner_variable/no_base
Normal file
0
tests/dictionaries/20override/no_base
Normal file
0
tests/dictionaries/20override/no_base
Normal file
0
tests/dictionaries/20override_no_templating/no_base
Normal file
0
tests/dictionaries/20override_no_templating/no_base
Normal file
0
tests/dictionaries/20override_source/no_base
Normal file
0
tests/dictionaries/20override_source/no_base
Normal file
0
tests/dictionaries/70service_disabled/no_base
Normal file
0
tests/dictionaries/70service_disabled/no_base
Normal file
0
tests/dictionaries/70service_engine/no_base
Normal file
0
tests/dictionaries/70service_engine/no_base
Normal file
0
tests/dictionaries/70service_engine_dash/no_base
Normal file
0
tests/dictionaries/70service_engine_dash/no_base
Normal file
0
tests/dictionaries/70service_mount/no_base
Normal file
0
tests/dictionaries/70service_mount/no_base
Normal file
0
tests/dictionaries/70service_servicelist_file/no_base
Normal file
0
tests/dictionaries/70service_servicelist_file/no_base
Normal file
0
tests/dictionaries/70service_servicelist_ip/no_base
Normal file
0
tests/dictionaries/70service_servicelist_ip/no_base
Normal file
0
tests/dictionaries/70service_target/no_base
Normal file
0
tests/dictionaries/70service_target/no_base
Normal file
0
tests/dictionaries/70service_target_engine/no_base
Normal file
0
tests/dictionaries/70service_target_engine/no_base
Normal file
0
tests/dictionaries/70service_timer/no_base
Normal file
0
tests/dictionaries/70service_timer/no_base
Normal file
0
tests/dictionaries/70services_ip/no_base
Normal file
0
tests/dictionaries/70services_ip/no_base
Normal file
0
tests/dictionaries/70services_ip_cidr/no_base
Normal file
0
tests/dictionaries/70services_ip_cidr/no_base
Normal file
0
tests/dictionaries/70services_ip_disabled/no_base
Normal file
0
tests/dictionaries/70services_ip_disabled/no_base
Normal file
0
tests/dictionaries/70services_ip_extra/no_base
Normal file
0
tests/dictionaries/70services_ip_extra/no_base
Normal file
0
tests/dictionaries/70services_ip_iplist/no_base
Normal file
0
tests/dictionaries/70services_ip_iplist/no_base
Normal file
0
tests/dictionaries/70services_ip_leadership/no_base
Normal file
0
tests/dictionaries/70services_ip_leadership/no_base
Normal file
0
tests/dictionaries/70services_ip_multi/no_base
Normal file
0
tests/dictionaries/70services_ip_multi/no_base
Normal file
0
tests/dictionaries/70services_ip_network/no_base
Normal file
0
tests/dictionaries/70services_ip_network/no_base
Normal file
0
tests/dictionaries/70services_ip_not_mandatory/no_base
Normal file
0
tests/dictionaries/70services_ip_not_mandatory/no_base
Normal file
0
tests/dictionaries/70services_ip_twice/no_base
Normal file
0
tests/dictionaries/70services_ip_twice/no_base
Normal file
|
@ -1,11 +1,11 @@
|
|||
from os import listdir, mkdir, readlink
|
||||
from os.path import join, isdir, isfile, islink
|
||||
from shutil import rmtree
|
||||
from pytest import fixture, mark
|
||||
from pytest import fixture, mark, raises
|
||||
from lxml.etree import parse
|
||||
from tiramisu import Config
|
||||
|
||||
from rougail import RougailConfig, RougailSystemdTemplate
|
||||
from rougail import RougailConfig, RougailBaseTemplate, RougailSystemdTemplate
|
||||
|
||||
|
||||
template_dirs = 'tests/dictionaries'
|
||||
|
@ -39,7 +39,7 @@ def find_files(dirname: str,
|
|||
files.add(join(*root_file))
|
||||
|
||||
|
||||
async def template(test_dir, filename, root):
|
||||
async def template(test_dir, filename, root, engine_name):
|
||||
test_dir = join(template_dirs, test_dir)
|
||||
tmp_dir = join(test_dir, '..', 'tmp')
|
||||
|
||||
|
@ -71,7 +71,10 @@ async def template(test_dir, filename, root):
|
|||
RougailConfig['tmpfile_dest_dir'] = '/test/new/file'
|
||||
else:
|
||||
RougailConfig['tmpfile_dest_dir'] = '/usr/local/lib'
|
||||
engine = RougailSystemdTemplate(config)
|
||||
if engine_name == 'base':
|
||||
engine = RougailBaseTemplate(config)
|
||||
else:
|
||||
engine = RougailSystemdTemplate(config)
|
||||
await engine.instance_files()
|
||||
list_templates = set()
|
||||
if isdir(dest_dir):
|
||||
|
@ -85,6 +88,8 @@ async def template(test_dir, filename, root):
|
|||
[],
|
||||
list_results,
|
||||
)
|
||||
if engine_name == 'base' and 'tmpfiles.d/0rougail.conf' in list_results:
|
||||
list_results.remove('tmpfiles.d/0rougail.conf')
|
||||
assert list_templates == list_results, f'error with {test_dir}:'
|
||||
for result in list_results:
|
||||
template_file = join(dest_dir, result)
|
||||
|
@ -99,20 +104,40 @@ async def template(test_dir, filename, root):
|
|||
with open(template_file, 'r') as fh:
|
||||
generated_file = fh.read()
|
||||
assert result_file == generated_file, f'{template_file} content : \n{generated_file}\nexpected: \nresult_file\n'
|
||||
rmtree(dest_dir)
|
||||
rmtree(tmp_dir)
|
||||
if isdir(dest_dir):
|
||||
rmtree(dest_dir)
|
||||
if isdir(tmp_dir):
|
||||
rmtree(tmp_dir)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_template(test_dir):
|
||||
await template(test_dir, 'base', '1')
|
||||
for engine in ['base', 'systemd']:
|
||||
not_file = join(template_dirs, test_dir, 'no_' + engine)
|
||||
if isfile(not_file):
|
||||
with raises(Exception) as err:
|
||||
await template(test_dir, 'base', '1', engine)
|
||||
else:
|
||||
await template(test_dir, 'base', '1', engine)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_template_multi_1(test_dir):
|
||||
await template(test_dir, 'multi', '1')
|
||||
for engine in ['base', 'systemd']:
|
||||
not_file = join(template_dirs, test_dir, 'no_' + engine)
|
||||
if isfile(not_file):
|
||||
with raises(Exception) as err:
|
||||
await template(test_dir, 'multi', '1', engine)
|
||||
else:
|
||||
await template(test_dir, 'multi', '1', engine)
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_template_multi_2(test_dir):
|
||||
await template(test_dir, 'multi', '1')
|
||||
for engine in ['base', 'systemd']:
|
||||
not_file = join(template_dirs, test_dir, 'no_' + engine)
|
||||
if isfile(not_file):
|
||||
with raises(Exception) as err:
|
||||
await template(test_dir, 'multi', '1', engine)
|
||||
else:
|
||||
await template(test_dir, 'multi', '1', engine)
|
||||
|
|
Loading…
Reference in a new issue