From af6b56cf737db6c013ec5040a787880492646416 Mon Sep 17 00:00:00 2001 From: GeorgianaElena Date: Mon, 8 Jun 2020 12:36:26 +0300 Subject: [PATCH] Update unit test --- docs/topic/escape-hatch.rst | 2 ++ tests/test_traefik.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/topic/escape-hatch.rst b/docs/topic/escape-hatch.rst index 608003d..f319516 100644 --- a/docs/topic/escape-hatch.rst +++ b/docs/topic/escape-hatch.rst @@ -63,3 +63,5 @@ proxy for the new configuration to take effect: .. code-block:: bash sudo tljh-config reload proxy + +.. warning:: This instructions might change when TLJH will switch to Traefik > 2.0 diff --git a/tests/test_traefik.py b/tests/test_traefik.py index 488418f..d22f68d 100644 --- a/tests/test_traefik.py +++ b/tests/test_traefik.py @@ -3,6 +3,7 @@ import os from unittest import mock import toml +import pytest from tljh import config from tljh import traefik @@ -127,8 +128,20 @@ def test_manual_ssl_config(tljh_dir): 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") + traefik_toml = os.path.join(state_dir, "traefik.toml") + + # Generate default config + traefik.ensure_traefik_config(str(state_dir)) + + # Read the default config + toml_cfg = toml.load(traefik_toml) + + # Make sure the defaults are what we expect + assert toml_cfg["logLevel"] == "INFO" + with pytest.raises(KeyError): + toml_cfg["checkNewVersion"] + assert toml_cfg["entryPoints"]["auth_api"]["address"] == "127.0.0.1:8099" extra_config = { # modify existing value @@ -146,11 +159,13 @@ def test_extra_config(tmpdir, tljh_dir): with open(os.path.join(extra_config_dir, "extra.toml"), "w+") as extra_config_file: toml.dump(extra_config, extra_config_file) - # This merges the 2 configs + # Merge the extra config with the defaults 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() + # Check that the defaults were updated by the extra config + assert toml_cfg["logLevel"] == "ERROR" + assert toml_cfg["checkNewVersion"] == False + assert toml_cfg["entryPoints"]["auth_api"]["address"] == "127.0.0.1:9999"