1
0
Fork 0

Organizing code to refactory labels

This commit is contained in:
Joao M 2022-08-12 01:00:18 +00:00
parent e89a329781
commit d278629671
3 changed files with 124 additions and 18 deletions

View file

@ -1,4 +1,4 @@
from .context import easymapping
import easymapping
import pytest
import os
import yaml
@ -7,20 +7,20 @@ import yaml
def load_fixture(file):
path = os.path.dirname(os.path.realpath(__file__))
with open(path + "/fixtures/" + file, 'r') as content_file:
lineList = content_file.readlines()
line_list = content_file.readlines()
return lineList
return line_list
def test_parser_doesnt_crash():
lineList = load_fixture("no-services")
line_list = load_fixture("no-services")
result = {
"customerrors": False
}
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
haproxy_config = cfg.generate(line_list)
assert len(haproxy_config) > 0
path = os.path.dirname(os.path.realpath(__file__))
@ -29,7 +29,7 @@ def test_parser_doesnt_crash():
def test_parser_finds_services():
lineList = load_fixture("services")
line_list = load_fixture("services")
result = {
"customerrors": False
@ -40,7 +40,7 @@ def test_parser_finds_services():
os.remove(cert_file)
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
haproxy_config = cfg.generate(line_list)
assert len(haproxy_config) > 0
path = os.path.dirname(os.path.realpath(__file__))
@ -51,7 +51,7 @@ def test_parser_finds_services():
assert expected_file.read() == "Some PEM Certificate"
def test_parser_finds_services_changed_label():
lineList = load_fixture("services-changed-label")
line_list = load_fixture("services-changed-label")
result = {
"customerrors": False,
@ -63,7 +63,7 @@ def test_parser_finds_services_changed_label():
os.remove(cert_file)
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
haproxy_config = cfg.generate(line_list)
assert len(haproxy_config) > 0
path = os.path.dirname(os.path.realpath(__file__))
@ -73,6 +73,91 @@ def test_parser_finds_services_changed_label():
with open(cert_file, 'r') as expected_file:
assert expected_file.read() == "Some PEM Certificate"
def test_parser_finds_services_raw():
line_list = load_fixture("services")
result = {
"customerrors": False
}
cert_file = "/tmp/www.somehost.com.br.1.pem"
if os.path.exists(cert_file):
os.remove(cert_file)
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
parsed_object = [
{
"mode":"tcp",
"health-check":"",
"port":"31339",
"hosts":{
"agent.quantum.example.org":[
"my-stack_agent:9001"
]
},
"redirect":{
}
},
{
"mode":"http",
"health-check":"",
"port":"31337",
"hosts":{
"cadvisor.quantum.example.org":[
"my-stack_cadvisor:8080"
],
"node-exporter.quantum.example.org":[
"my-stack_node-exporter:9100"
]
},
"redirect":{
}
},
{
"mode":"http",
"health-check":"",
"port":"80",
"hosts":{
"www.somehost.com.br":[
"some-service:80"
]
},
"redirect":{
"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"
}
},
{
"mode":"http",
"health-check":"",
"port":"443",
"hosts":{
"www.somehost.com.br":[
"some-service:80"
]
},
"redirect":{
"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"
},
"ssl_cert":"/tmp/www.somehost.com.br.1.pem"
}
]
processed = list(cfg.parse(line_list))
assert parsed_object == processed
def test_parser_static():
path = os.path.dirname(os.path.realpath(__file__))
@ -88,14 +173,14 @@ def test_parser_static():
def test_parser_tcp():
lineList = load_fixture("services-tcp")
line_list = load_fixture("services-tcp")
result = {
"customerrors": False
}
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
haproxy_config = cfg.generate(line_list)
# print(haproxy_config)
assert len(haproxy_config) > 0
@ -104,17 +189,19 @@ def test_parser_tcp():
assert expected_file.read() == haproxy_config
def test_parser_multi_containers():
lineList = load_fixture("services-multi-containers")
line_list = load_fixture("services-multi-containers")
result = {
"customerrors": False
}
cfg = easymapping.HaproxyConfigGenerator(result, "/tmp")
haproxy_config = cfg.generate(lineList)
haproxy_config = cfg.generate(line_list)
assert len(haproxy_config) > 0
path = os.path.dirname(os.path.realpath(__file__))
with open(path + "/expected/services-multi-containers.txt", 'r') as expected_file:
assert expected_file.read() == haproxy_config
#test_parser_finds_services_raw()