forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_config.py
More file actions
86 lines (63 loc) · 2.94 KB
/
test_config.py
File metadata and controls
86 lines (63 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pytest
from testcontainers.core.config import (
TestcontainersConfiguration as TCC,
TC_FILE,
get_user_overwritten_connection_mode,
ConnectionMode,
)
from pytest import MonkeyPatch, mark, LogCaptureFixture
import logging
import tempfile
def test_read_tc_properties(monkeypatch: MonkeyPatch) -> None:
with tempfile.TemporaryDirectory() as tmpdirname:
file = f"{tmpdirname}/{TC_FILE}"
with open(file, "w") as f:
f.write("tc.host=some_value\n")
monkeypatch.setattr("testcontainers.core.config.TC_GLOBAL", file)
config = TCC()
assert config.tc_properties == {"tc.host": "some_value"}
@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)
config = TCC()
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:
config = TCC()
config.tc_properties = {"tc.host": "some_value"}
assert config.tc_properties_get_tc_host() == "some_value"
def test_timeout() -> None:
config = TCC()
config.max_tries = 2
config.sleep_time = 3
assert config.timeout == 6
def test_invalid_connection_mode(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("TESTCONTAINERS_CONNECTION_MODE", "FOOBAR")
with pytest.raises(ValueError, match="Error parsing TESTCONTAINERS_CONNECTION_MODE.*FOOBAR.*"):
get_user_overwritten_connection_mode()
@pytest.mark.parametrize("mode, use_mapped", (("bridge_ip", False), ("gateway_ip", True), ("docker_host", True)))
def test_valid_connection_mode(monkeypatch: pytest.MonkeyPatch, mode: str, use_mapped: bool) -> None:
monkeypatch.setenv("TESTCONTAINERS_CONNECTION_MODE", mode)
assert get_user_overwritten_connection_mode().use_mapped_port is use_mapped
def test_no_connection_mode_given(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("TESTCONTAINERS_CONNECTION_MODE", raising=False)
assert get_user_overwritten_connection_mode() is None