mirror of https://github.com/docker/docker-py.git
Fix log driver integration test
By using `json-file` as the use case we can run this without needing to be on a machine with syslog installed. Even if syslog was installed, this test was still failing as the `log_opt` of 'key1' is an invalid option. This test is slightly different style to the others, it hopefully includes an example of how to space out tests for increased readability, we construct our tests in 3 phases(generally) and include a space imbetween them: - setup - perform action - assertions Expanded variable names is important for readability/clarity. Also reduced the number of assertions to focus on the logic we're testing. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
d60cb3172e
commit
90538cf0a3
|
@ -245,30 +245,25 @@ class TestCreateContainerWithRoBinds(BaseTestCase):
|
|||
self.assertFalse(inspect_data['VolumesRW'][mount_dest])
|
||||
|
||||
|
||||
@unittest.skipIf(NOT_ON_HOST, 'Tests running inside a container; no syslog')
|
||||
class TestCreateContainerWithLogConfig(BaseTestCase):
|
||||
def runTest(self):
|
||||
config = docker.utils.LogConfig(
|
||||
type=docker.utils.LogConfig.types.SYSLOG,
|
||||
config={'key1': 'val1'}
|
||||
class CreateContainerWithLogConfigTest(BaseTestCase):
|
||||
def test_valid_log_driver_and_log_opt(self):
|
||||
log_config = docker.utils.LogConfig(
|
||||
type='json-file',
|
||||
config={'max-file': '100'}
|
||||
)
|
||||
ctnr = self.client.create_container(
|
||||
|
||||
container = self.client.create_container(
|
||||
'busybox', ['true'],
|
||||
host_config=self.client.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)
|
||||
self.tmp_containers.append(container['Id'])
|
||||
self.client.start(container)
|
||||
|
||||
info = self.client.inspect_container(container)
|
||||
container_log_config = info['HostConfig']['LogConfig']
|
||||
|
||||
self.assertEqual(container_log_config['Type'], log_config.type)
|
||||
self.assertEqual(container_log_config['Config'], log_config.config)
|
||||
|
||||
|
||||
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')
|
||||
|
|
Loading…
Reference in New Issue