|
5 | 5 | from testcontainers.core.container import DockerContainer |
6 | 6 | from testcontainers.core.docker_client import DockerClient |
7 | 7 | from testcontainers.core.config import ConnectionMode |
| 8 | +from testcontainers.core.config import testcontainers_config |
8 | 9 |
|
9 | 10 | FAKE_ID = "ABC123" |
10 | 11 |
|
@@ -103,6 +104,28 @@ def test_attribute(init_attr, init_value, class_attr, stored_value): |
103 | 104 | assert getattr(container, class_attr) == stored_value |
104 | 105 |
|
105 | 106 |
|
| 107 | +def test_image_prefix_applied(monkeypatch: pytest.MonkeyPatch) -> None: |
| 108 | + """Test that the hub_image_name_prefix is properly applied to the image name.""" |
| 109 | + |
| 110 | + # Set a prefix |
| 111 | + test_prefix = "myregistry.example.com/" |
| 112 | + monkeypatch.setattr(testcontainers_config, "hub_image_name_prefix", test_prefix) |
| 113 | + |
| 114 | + # Create a container and verify the prefix is applied |
| 115 | + container = DockerContainer("nginx:latest") |
| 116 | + assert container.image == "myregistry.example.com/nginx:latest" |
| 117 | + |
| 118 | + |
| 119 | +def test_image_no_prefix_applied_when_empty(monkeypatch: pytest.MonkeyPatch) -> None: |
| 120 | + """Test that when hub_image_name_prefix is empty, no prefix is applied.""" |
| 121 | + # Set an empty prefix |
| 122 | + monkeypatch.setattr(testcontainers_config, "hub_image_name_prefix", "") |
| 123 | + |
| 124 | + # Create a container and verify no prefix is applied |
| 125 | + container = DockerContainer("nginx:latest") |
| 126 | + assert container.image == "nginx:latest" |
| 127 | + |
| 128 | + |
106 | 129 | def test_container_info(): |
107 | 130 | """Test get_container_info functionality with a real container.""" |
108 | 131 | with DockerContainer("alpine:latest").with_command("sleep 30") as container: |
|
0 commit comments