Enable renaming templates

pull/3/head
Christophe Mehay 8 years ago
parent dada1a0dcf
commit 69c18e6954

@ -7,6 +7,7 @@ RUN pip install pytest six pyyaml jinja2 colorlog
ENV PYTHONPATH /opt/
ADD tests/test_template.yml.tpl /tmp/test_template.yml
ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl
WORKDIR /opt/tests

@ -7,6 +7,7 @@ RUN pip3 install pytest six pyyaml jinja2 colorlog
ENV PYTHONPATH /opt/
ADD tests/test_template.yml.tpl /tmp/test_template.yml
ADD tests/test_template.yml.tpl /tmp/test_template2.yml.tpl
WORKDIR /opt/tests

@ -75,9 +75,10 @@ group: 1000
# These files should exist (ADD or COPY)
# and should be jinja templated.
# Note: if config files end with ".tpl", the extension will be removed.
config_files:
- /etc/gitconfig
- .ssh/config
- .ssh/config.tpl # Will apply to ".ssh/config"
- .ssh/id_rsa
# These environment variables will be wiped before
@ -222,7 +223,7 @@ You have 4 available objects in your templates.
Some setups can be overridden using environment variables.
- `ENTRYPOINT_CONFIG` overrides `entrypoint-config.yml` file.
- `ENTRYPOINT_CONFIG` overrides path of `entrypoint-config.yml` file.
### Running Tests

@ -49,6 +49,8 @@ class Entrypoint(object):
env = Environment(loader=FileSystemLoader('/'))
for template in self.config.config_files:
temp = env.get_template(template)
if template.endswith('.tpl'):
template = template[:-4]
with open(template, mode='w') as f:
self.log.debug('Applying conf to {}'.format(template))
f.write(temp.render(config=self.config,

@ -5,6 +5,7 @@ group: 1000
config_files:
- /tmp/test_template.yml
- /tmp/test_template2.yml.tpl
secret_env:
- SECRET

@ -109,37 +109,40 @@ def test_templates():
entry.apply_conf()
with open(conf.config_files[0], mode='r') as r:
test = load(stream=r, Loader=Loader)
assert len(set(test['All links'])) == 4
assert len(set(test['All links 1'])) == 2
assert len(set(test['All links 2'])) == 2
assert fnmatch.fnmatch(test['Links 2 800'][0], 'udp://*:800')
# test environment
assert test['All environ']['FOO'] == 'bar'
assert test['All links 2 environ']['FOO'] == 'bar'
test_names = [
'test1',
'test2',
'test3',
'test4',
]
# test names
for test_name in test_names:
assert test_name in test['All names']
# test id
for id in test['ID']:
int(id, base=16)
# test env
assert test['ENV']['SECRET'] == 'nothing'
assert test['ENVIRON']['SECRET'] == 'nothing'
for config_file in conf.config_files:
if config_file.endswith('.tpl'):
config_file = config_file[:-4]
with open(conf.config_files[0], mode='r') as r:
test = load(stream=r, Loader=Loader)
assert len(set(test['All links'])) == 4
assert len(set(test['All links 1'])) == 2
assert len(set(test['All links 2'])) == 2
assert fnmatch.fnmatch(test['Links 2 800'][0], 'udp://*:800')
# test environment
assert test['All environ']['FOO'] == 'bar'
assert test['All links 2 environ']['FOO'] == 'bar'
test_names = [
'test1',
'test2',
'test3',
'test4',
]
# test names
for test_name in test_names:
assert test_name in test['All names']
# test id
for id in test['ID']:
int(id, base=16)
# test env
assert test['ENV']['SECRET'] == 'nothing'
assert test['ENVIRON']['SECRET'] == 'nothing'
def test_conf_commands():

Loading…
Cancel
Save