1
0
Fork 0

Add unit tests

This commit is contained in:
Joao M 2022-08-11 22:18:28 +00:00
parent 2ef8dfecb9
commit c6bef882ca
4 changed files with 41 additions and 2 deletions

6
tests/fixtures/services-changed-label vendored Normal file
View file

@ -0,0 +1,6 @@
portainer-agent_agent={"com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"portainer-agent"}
my-stack_agent={"haproxy.definitions":"agent","haproxy.host.agent":"agent.quantum.example.org","haproxy.localport.agent":"9001","haproxy.mode.agent":"tcp","haproxy.port.agent":"31339","com.docker.stack.image":"portainer/agent:1.5.1","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_cadvisor={"haproxy.definitions":"cadvisor","haproxy.host.cadvisor":"cadvisor.quantum.example.org","haproxy.localport.cadvisor":"8080","haproxy.port.cadvisor":"31337","com.docker.stack.image":"gcr.io/google-containers/cadvisor:v0.34.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_node-exporter={"haproxy.definitions":"exp","haproxy.host.exp":"node-exporter.quantum.example.org","haproxy.localport.exp":"9100","haproxy.port.exp":"31337","com.docker.stack.image":"stefanprodan/swarmprom-node-exporter:v0.16.0","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
my-stack_reverse-proxy={"com.docker.stack.image":"quay.io/pngmbh/easy-haproxy:tcp-mode","com.docker.stack.namespace":"my-stack","com.planetary-quantum":"monitoring"}
some-service={"haproxy.definitions":"http,https","haproxy.port.http":"80","haproxy.host.http":"www.somehost.com.br","haproxy.localport.http":"80","haproxy.redirect.http":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.port.https":"443","haproxy.host.https":"www.somehost.com.br","haproxy.localport.https":"80","haproxy.redirect.https":"somehost.com.br--https://www.somehost.com.br,somehost.com--https://www.somehost.com.br,www.somehost.com--https://www.somehost.com.br,byjg.ca--https://www.somehost.com.br,www.byjg.ca--https://www.somehost.com.br","haproxy.sslcert.https":"U29tZSBQRU0gQ2VydGlmaWNhdGU="}

View file

@ -50,6 +50,29 @@ def test_parser_finds_services():
with open(cert_file, 'r') as expected_file:
assert expected_file.read() == "Some PEM Certificate"
def test_parser_finds_services_changed_label():
lineList = load_fixture("services-changed-label")
result = {
"customerrors": False,
"lookup_label": "haproxy"
}
cert_file = "/tmp/www.somehost.com.br.1.pem"
if os.path.exists(cert_file):
os.remove(cert_file)
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
assert len(haproxy_config) > 0
path = os.path.dirname(os.path.realpath(__file__))
with open(path + "/expected/services.txt", 'r') as expected_file:
assert expected_file.read() == haproxy_config
with open(cert_file, 'r') as expected_file:
assert expected_file.read() == "Some PEM Certificate"
def test_parser_static():
path = os.path.dirname(os.path.realpath(__file__))