This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/conf/init/test/test_supervisord_conf_create.py
Jimmy Zelinskie 8e3780ed5c conf/init: add validate supervisord config test
This test replaces the previous test that made sure jinja templated to
an exact match of what is expected. This was brittle and required that
both be maintained synchrously. This replacement test instead verifies
that what jinja generates validates when parsed by supervisord.
2019-11-21 16:22:29 -05:00

53 lines
1.4 KiB
Python

from contextlib import contextmanager
import os
import tempfile
from six import iteritems
from supervisor.options import ServerOptions
import jinja2
import pytest
from ..supervisord_conf_create import (default_services, limit_services, override_services,
QUAY_SERVICES, QUAY_OVERRIDE_SERVICES)
@contextmanager
def environ(**kwargs):
original_env = {key: os.getenv(key) for key in kwargs}
os.environ.update(**kwargs)
try:
yield
finally:
for key, value in iteritems(original_env):
if value is None:
del os.environ[key]
else:
os.environ[key] = value
def render_supervisord_conf(config):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../supervisord.conf.jnj")) as f:
template = jinja2.Template(f.read())
return template.render(config=config)
def test_supervisord_conf_validates():
config = default_services()
limit_services(config, QUAY_SERVICES)
override_services(config, QUAY_OVERRIDE_SERVICES)
rendered_config_file = render_supervisord_conf(config)
print rendered_config_file
with environ(QUAYPATH='.', QUAYDIR='/', QUAYCONF='/conf', DB_CONNECTION_POOLING_REGISTRY='true'):
opts = ServerOptions()
with tempfile.NamedTemporaryFile() as f:
f.write(rendered_config_file)
f.flush()
opts.searchpaths = [f.name]
assert opts.default_configfile() == f.name
opts.realize([])
opts.process_config()