1
0
Fork 0

Refactor E2E tests and configuration format

- Replaced `easymapping` configuration with `containers` for better maintainability and clarity.
- Introduced `DockerComposeFixture` class in `utils.py` to manage Docker Compose lifecycle and smart build strategy.
- Enhanced YAML-to-environment variable conversion in `ContainerEnv` for dynamic configuration support.
- Updated HAProxy configurations and test fixtures to reflect the new format.
- Improved test coverage for YAML parsing, environment variable handling, and HAProxy config generation.
This commit is contained in:
Joao Gilberto Magalhaes 2026-02-13 11:44:26 -05:00
parent c125985150
commit 97845b8a52
22 changed files with 1042 additions and 442 deletions

View file

@ -8,58 +8,46 @@ def test_processor_static():
ProcessorInterface.static_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "./fixtures/static.yml")
static = ProcessorInterface.factory(ProcessorInterface.STATIC)
parsed_object = [
{
"hosts": {
"host1.com.br": {
"containers": [
"container:5000"
],
"certbot": True
},
"host2.com.br": {
"containers": [
"other:3000"
]
}
},
"port": 80,
"redirect": {
"www.host1.com.br": "http://host1.com.br"
}
# New format: parsed_object is a dict mapping container IPs to their labels
# Note: 'container' now has labels for BOTH host1.com.br:80 and host1.com.br:443
parsed_object = {
'container': {
'easyhaproxy.host1_com_br_80.host': 'host1.com.br',
'easyhaproxy.host1_com_br_80.port': '80',
'easyhaproxy.host1_com_br_80.localport': '5000',
'easyhaproxy.host1_com_br_80.certbot': 'true',
'easyhaproxy.host1_com_br_443.host': 'host1.com.br',
'easyhaproxy.host1_com_br_443.port': '443',
'easyhaproxy.host1_com_br_443.localport': '80',
'easyhaproxy.host1_com_br_443.ssl': 'true',
},
{
"hosts": {
"host1.com.br": {
"containers": [
"container:80"
]
}
},
"port": 443,
"ssl": True
'other': {
'easyhaproxy.host2_com_br_80.host': 'host2.com.br',
'easyhaproxy.host2_com_br_80.port': '80',
'easyhaproxy.host2_com_br_80.localport': '3000',
},
{
"hosts": {
"host3.com.br": {
"containers": [
"domain:8181"
]
}
},
"port": 8080
}
]
'redirect-www.host1.com.br-80': {
'easyhaproxy.www_host1_com_br_80.host': 'www.host1.com.br',
'easyhaproxy.www_host1_com_br_80.port': '80',
'easyhaproxy.www_host1_com_br_80.redirect': '{"www.host1.com.br": "http://host1.com.br"}',
'easyhaproxy.www_host1_com_br_80.redirect_only': 'true',
},
'domain': {
'easyhaproxy.host3_com_br_8080.host': 'host3.com.br',
'easyhaproxy.host3_com_br_8080.port': '8080',
'easyhaproxy.host3_com_br_8080.localport': '8181',
},
}
hosts = [
'host1.com.br:443',
'host1.com.br:80',
'host2.com.br:80',
'host1.com.br:443',
'host3.com.br:8080'
]
assert static.get_certbot_hosts() is None
assert static.get_parsed_object() == parsed_object
assert static.get_hosts() == hosts
assert static.get_hosts() is None
haproxy_cfg = static.get_haproxy_conf()
@ -67,8 +55,39 @@ def test_processor_static():
os.path.join(os.path.dirname(os.path.realpath(__file__)), "./expected/static.txt"))
# @todo: Static doesnt populate this fields
assert static.get_certbot_hosts() == []
assert static.get_certbot_hosts() == ['host1.com.br']
assert static.get_parsed_object() == parsed_object
assert static.get_hosts() == hosts
def test_processor_static_multiple_domains_same_container():
"""Test that multiple domains can point to the same backend container"""
ProcessorInterface.static_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"./fixtures/static_multi_domain.yml"
)
static = ProcessorInterface.factory(ProcessorInterface.STATIC)
parsed_object = static.get_parsed_object()
# Should have labels for both host1 and host2 on the same container
assert 'webapp' in parsed_object
webapp_labels = parsed_object['webapp']
# Check both host definitions are present (this is the key test - both should exist!)
assert 'easyhaproxy.host1_com_80.host' in webapp_labels
assert 'easyhaproxy.host2_com_80.host' in webapp_labels
assert webapp_labels['easyhaproxy.host1_com_80.host'] == 'host1.com'
assert webapp_labels['easyhaproxy.host2_com_80.host'] == 'host2.com'
# Generate HAProxy config
haproxy_cfg = static.get_haproxy_conf()
# Verify both backends are created
assert 'backend srv_host1_com_80' in haproxy_cfg
assert 'backend srv_host2_com_80' in haproxy_cfg
# Both should point to the same container
assert haproxy_cfg.count('server srv-0 webapp:8080') == 2
# test_processor_static()