summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2015-04-24 15:10:51 -0700
committerJoffrey F <joffrey@docker.com>2015-04-24 15:10:51 -0700
commitc7948436e54dd7e12cc062aebcfd46328427715f (patch)
tree5ffd73ad36518c43b9578937dee82cf8b3ecab32
parent21d80b16ddb67b1d95b62b56dad1b91a7986333f (diff)
downloaddocker-py-logconfig-support.tar.gz
Added tests for log_config paramlogconfig-support
-rw-r--r--tests/integration_test.py27
-rw-r--r--tests/utils_test.py22
2 files changed, 47 insertions, 2 deletions
diff --git a/tests/integration_test.py b/tests/integration_test.py
index eb7a0eb..21679d7 100644
--- a/tests/integration_test.py
+++ b/tests/integration_test.py
@@ -348,6 +348,31 @@ class TestStartContainerWithFileBind(BaseTestCase):
os.unlink(mount_origin)
+class TestCreateContainerWithLogConfig(BaseTestCase):
+ def runTest(self):
+ config = docker.utils.LogConfig(
+ type=docker.utils.LogConfig.types.SYSLOG,
+ config={'key1': 'val1'}
+ )
+ ctnr = self.client.create_container(
+ 'busybox', ['true'],
+ host_config=create_host_config(log_config=config)
+ )
+ self.assertIn('Id', ctnr)
+ self.tmp_containers.append(ctnr['Id'])
+ self.client.start(ctnr)
+ info = self.client.inspect_container(ctnr)
+ self.assertIn('HostConfig', info)
+ host_config = info['HostConfig']
+ self.assertIn('LogConfig', host_config)
+ log_config = host_config['LogConfig']
+ self.assertIn('Type', log_config)
+ self.assertEqual(log_config['Type'], config.type)
+ self.assertIn('Config', log_config)
+ self.assertEqual(type(log_config['Config']), dict)
+ self.assertEqual(log_config['Config'], config.config)
+
+
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
class TestCreateContainerReadOnlyFs(BaseTestCase):
def runTest(self):
@@ -958,7 +983,7 @@ class TestStartContainerWithVolumesFrom(BaseTestCase):
class TestStartContainerWithUlimits(BaseTestCase):
def runTest(self):
- ulimit = docker.utils.Ulimit('nofile', 4096, 4096)
+ ulimit = docker.utils.Ulimit(name='nofile', soft=4096, hard=4096)
res0 = self.client.create_container('busybox', 'true')
container1_id = res0['Id']
diff --git a/tests/utils_test.py b/tests/utils_test.py
index 1f18512..454a14e 100644
--- a/tests/utils_test.py
+++ b/tests/utils_test.py
@@ -6,7 +6,7 @@ from docker.client import Client
from docker.errors import DockerException
from docker.utils import (
parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
- create_host_config, Ulimit
+ create_host_config, Ulimit, LogConfig
)
from docker.utils.ports import build_port_bindings, split_port
from docker.auth import resolve_authconfig
@@ -141,6 +141,26 @@ class UtilsTest(base.BaseTestCase):
self.assertRaises(ValueError, lambda: Ulimit(name='hello', soft='123'))
self.assertRaises(ValueError, lambda: Ulimit(name='hello', hard='456'))
+ def test_create_host_config_dict_logconfig(self):
+ dct = {'type': LogConfig.types.SYSLOG, 'config': {'key1': 'val1'}}
+ config = create_host_config(log_config=dct)
+ self.assertIn('LogConfig', config)
+ self.assertTrue(isinstance(config['LogConfig'], LogConfig))
+ self.assertEqual(dct['type'], config['LogConfig'].type)
+
+ def test_create_host_config_obj_logconfig(self):
+ obj = LogConfig(type=LogConfig.types.SYSLOG, config={'key1': 'val1'})
+ config = create_host_config(log_config=obj)
+ self.assertIn('LogConfig', config)
+ self.assertTrue(isinstance(config['LogConfig'], LogConfig))
+ self.assertEqual(obj, config['LogConfig'])
+
+ def test_logconfig_invalid_type(self):
+ self.assertRaises(ValueError, lambda: LogConfig(type='xxx', config={}))
+ self.assertRaises(ValueError, lambda: LogConfig(
+ type=LogConfig.types.JSON, config='helloworld'
+ ))
+
def test_resolve_authconfig(self):
auth_config = {
'https://index.docker.io/v1/': {'auth': 'indexuser'},