mirror of https://github.com/docker/docker-py.git
Added tests for log_config param
This commit is contained in:
parent
21d80b16dd
commit
c7948436e5
|
@ -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']
|
||||
|
|
|
@ -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'},
|
||||
|
|
Loading…
Reference in New Issue