testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.51k stars 281 forks source link

chore(core): Adds integration testing to the private registry auth feature (DOCKER_AUTH_CONFIG) #582

Closed Tranquility2 closed 3 months ago

Tranquility2 commented 3 months ago

Follow up on #566 - Testing using the registry module

Tranquility2 commented 3 months ago

Also fiddled with

+from unittest import mock
+
 from docker.errors import NotFound

 from testcontainers.core.container import DockerContainer
 from testcontainers.core.docker_client import DockerClient
 from testcontainers.core.waiting_utils import wait_container_is_ready
+from testcontainers.core.config import testcontainers_config as c

 from testcontainers.registry import DockerRegistryContainer

@@ -31,8 +34,7 @@ def test_missing_on_private_registry(monkeypatch):
         # prepare auth config
         creds: bytes = base64.b64encode(f"{username}:{password}".encode("utf-8"))
         config = {"auths": {f"{registry_url}": {"auth": creds.decode("utf-8")}}}
-        monkeypatch.setenv("DOCKER_AUTH_CONFIG", json.dumps(config))
-        assert os.environ.get("DOCKER_AUTH_CONFIG"), "DOCKER_AUTH_CONFIG not set"
+        mock.patch.object(c, "_docker_auth_config", json.dumps(config))
Tranquility2 commented 3 months ago

Nicely done @alexanderankin , thank you 🙏