summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAanand Prasad <aanand.prasad@gmail.com>2015-07-21 16:50:41 +0100
committerAanand Prasad <aanand.prasad@gmail.com>2015-07-21 16:50:44 +0100
commit75cc50f0ad2c0d39126f3dd1112235d338d78c4d (patch)
treeb29ecc68a2935f85004d592101945450d4809ebe /tests
parent2c08ad21dd9aa0c01936e6184574cd105a2b3f64 (diff)
downloaddocker-py-75cc50f0ad2c0d39126f3dd1112235d338d78c4d.tar.gz
Default to ~/.docker if DOCKER_CERT_PATH is empty
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/utils_test.py40
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/utils_test.py b/tests/utils_test.py
index 1c8729c..bacb0f0 100644
--- a/tests/utils_test.py
+++ b/tests/utils_test.py
@@ -1,5 +1,7 @@
import os
import os.path
+import shutil
+import tempfile
import unittest
from docker.client import Client
@@ -13,6 +15,11 @@ from docker.auth import resolve_repository_name, resolve_authconfig
import base
+TEST_CERT_DIR = os.path.join(
+ os.path.dirname(__file__),
+ 'testdata/certs',
+)
+
class UtilsTest(base.BaseTestCase):
longMessage = True
@@ -75,11 +82,18 @@ class UtilsTest(base.BaseTestCase):
for host, expected in valid_hosts.items():
self.assertEqual(parse_host(host), expected, msg=host)
- def test_kwargs_from_env(self):
+ def test_kwargs_from_env_empty(self):
+ os.environ.update(DOCKER_HOST='',
+ DOCKER_CERT_PATH='',
+ DOCKER_TLS_VERIFY='')
+
+ kwargs = kwargs_from_env()
+ self.assertEqual(None, kwargs.get('base_url'))
+ self.assertEqual(None, kwargs.get('tls'))
+
+ def test_kwargs_from_env_tls(self):
os.environ.update(DOCKER_HOST='tcp://192.168.59.103:2376',
- DOCKER_CERT_PATH=os.path.join(
- os.path.dirname(__file__),
- 'testdata/certs'),
+ DOCKER_CERT_PATH=TEST_CERT_DIR,
DOCKER_TLS_VERIFY='1')
kwargs = kwargs_from_env(assert_hostname=False)
self.assertEqual('https://192.168.59.103:2376', kwargs['base_url'])
@@ -95,6 +109,24 @@ class UtilsTest(base.BaseTestCase):
except TypeError as e:
self.fail(e)
+ def test_kwargs_from_env_no_cert_path(self):
+ try:
+ temp_dir = tempfile.mkdtemp()
+ cert_dir = os.path.join(temp_dir, '.docker')
+ shutil.copytree(TEST_CERT_DIR, cert_dir)
+
+ os.environ.update(HOME=temp_dir,
+ DOCKER_CERT_PATH='',
+ DOCKER_TLS_VERIFY='1')
+
+ kwargs = kwargs_from_env()
+ self.assertIn(cert_dir, kwargs['tls'].verify)
+ self.assertIn(cert_dir, kwargs['tls'].cert[0])
+ self.assertIn(cert_dir, kwargs['tls'].cert[1])
+ finally:
+ if temp_dir:
+ shutil.rmtree(temp_dir)
+
def test_convert_filters(self):
tests = [
({'dangling': True}, '{"dangling": ["true"]}'),