def test_docker_ip_remote_invalid(docker_host): environ = {"DOCKER_HOST": docker_host} with mock.patch("os.environ", environ): with pytest.raises(ValueError) as exc: print(get_docker_ip()) assert str(exc.value) == ('Invalid value for DOCKER_HOST: "%s".' % (docker_host, ))
def test_docker_ip_native(): environ = {} with mock.patch("os.environ", environ): assert get_docker_ip() == "127.0.0.1"
def docker_ip(): """Determine the IP address for TCP connections to Docker containers.""" return get_docker_ip()
def test_docker_ip_remote(): environ = {"DOCKER_HOST": "tcp://1.2.3.4:2376"} with mock.patch("os.environ", environ): assert get_docker_ip() == "1.2.3.4"
def test_docker_ip_unix(): environ = {"DOCKER_HOST": "unix:///run/user/1000/podman/podman.sock"} with mock.patch("os.environ", environ): assert get_docker_ip() == "127.0.0.1"