From 8b7b487ef4ea92812742225a6294a2abb06e3512 Mon Sep 17 00:00:00 2001 From: Roy Moore Date: Sat, 24 Aug 2024 16:40:50 +0000 Subject: [PATCH] full test_docker_auth_config --- core/tests/test_config.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/core/tests/test_config.py b/core/tests/test_config.py index f4167424..81e746ee 100644 --- a/core/tests/test_config.py +++ b/core/tests/test_config.py @@ -1,11 +1,39 @@ -from testcontainers.core.config import TestcontainersConfiguration as TCC +from testcontainers.core.config import TestcontainersConfiguration as TCC, _WARNINGS +from pytest import MonkeyPatch, mark, LogCaptureFixture + +import logging + + +@mark.parametrize("docker_auth_config_env", ["key=value", ""]) +@mark.parametrize("warning_dict", [{}, {"key": "value"}, {"DOCKER_AUTH_CONFIG": "TEST"}]) +@mark.parametrize("warning_dict_post", [{}, {"key": "value"}, {"DOCKER_AUTH_CONFIG": "TEST"}]) +def test_docker_auth_config( + caplog: LogCaptureFixture, + monkeypatch: MonkeyPatch, + docker_auth_config_env: str, + warning_dict: dict[str, str], + warning_dict_post: dict[str, str], +) -> None: + monkeypatch.setattr("testcontainers.core.config._WARNINGS", warning_dict) + monkeypatch.setenv("DOCKER_AUTH_CONFIG", docker_auth_config_env) + caplog.set_level(logging.WARNING) -def test_docker_auth_config() -> None: config = TCC() - assert config.docker_auth_config is None - config.docker_auth_config = "value" - assert config.docker_auth_config == "value" + if not docker_auth_config_env: + assert config.docker_auth_config == "" + assert caplog.text == "" + else: + assert config.docker_auth_config == docker_auth_config_env + + if "DOCKER_AUTH_CONFIG" in warning_dict: + assert warning_dict["DOCKER_AUTH_CONFIG"] in caplog.text + + if warning_dict == {}: + monkeypatch.setattr("testcontainers.core.config._WARNINGS", warning_dict_post) + + config.docker_auth_config = "new_value" + assert config.docker_auth_config == "new_value" def test_tc_properties_get_tc_host() -> None: