From 54bc95668b4a4d2f7c111bb58dc3d68946b77115 Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Tue, 2 Jun 2020 18:20:28 +0300 Subject: [PATCH] Test Traefik extra config --- tests/conftest.py | 1 + tests/test_traefik.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 77262e1..7d4ec37 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,4 +22,5 @@ def tljh_dir(tmpdir): assert tljh.config.INSTALL_PREFIX == tljh_dir os.makedirs(tljh.config.STATE_DIR) os.makedirs(tljh.config.CONFIG_DIR) + os.makedirs(os.path.join(tljh.config.CONFIG_DIR, "traefik_config.d")) yield tljh_dir diff --git a/tests/test_traefik.py b/tests/test_traefik.py index e15be9c..863b414 100644 --- a/tests/test_traefik.py +++ b/tests/test_traefik.py @@ -2,7 +2,7 @@ import os from unittest import mock -import pytoml as toml +import toml from tljh import config from tljh import traefik @@ -124,3 +124,33 @@ def test_manual_ssl_config(tljh_dir): "whiteList": {"sourceRange": ["127.0.0.1"]} }, } + +def test_extra_config(tmpdir, tljh_dir): + extra_config_dir = os.path.join(tljh_dir, config.CONFIG_DIR, "traefik_config.d") + + state_dir = tmpdir.mkdir("state") + + extra_config = { + # modify existing value + "dashboard": True, + # modify existing value with multiple levels + "entryPoints": { + "auth_api": { + "address": "127.0.0.1:9999" + } + }, + # add new setting + "checkNewVersion": False + } + + with open(os.path.join(extra_config_dir, "extra.py"), "w+") as extra_config_file: + toml.dump(extra_config, extra_config_file) + + # This merges the 2 configs + traefik.ensure_traefik_config(str(state_dir)) + traefik_toml = os.path.join(state_dir, "traefik.toml") + + # Read back the merged config + toml_cfg = toml.load(traefik_toml) + + assert extra_config.items() <= toml_cfg.items()