Skip to content

Commit 90538cf

Browse files
committed
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 <[email protected]>
1 parent d60cb31 commit 90538cf

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

tests/integration_test.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,25 @@ def runTest(self):
245245
self.assertFalse(inspect_data['VolumesRW'][mount_dest])
246246

247247

248-
@unittest.skipIf(NOT_ON_HOST, 'Tests running inside a container; no syslog')
249-
class TestCreateContainerWithLogConfig(BaseTestCase):
250-
def runTest(self):
251-
config = docker.utils.LogConfig(
252-
type=docker.utils.LogConfig.types.SYSLOG,
253-
config={'key1': 'val1'}
248+
class CreateContainerWithLogConfigTest(BaseTestCase):
249+
def test_valid_log_driver_and_log_opt(self):
250+
log_config = docker.utils.LogConfig(
251+
type='json-file',
252+
config={'max-file': '100'}
254253
)
255-
ctnr = self.client.create_container(
254+
255+
container = self.client.create_container(
256256
'busybox', ['true'],
257257
host_config=self.client.create_host_config(log_config=config)
258258
)
259-
self.assertIn('Id', ctnr)
260-
self.tmp_containers.append(ctnr['Id'])
261-
self.client.start(ctnr)
262-
info = self.client.inspect_container(ctnr)
263-
self.assertIn('HostConfig', info)
264-
host_config = info['HostConfig']
265-
self.assertIn('LogConfig', host_config)
266-
log_config = host_config['LogConfig']
267-
self.assertIn('Type', log_config)
268-
self.assertEqual(log_config['Type'], config.type)
269-
self.assertIn('Config', log_config)
270-
self.assertEqual(type(log_config['Config']), dict)
271-
self.assertEqual(log_config['Config'], config.config)
259+
self.tmp_containers.append(container['Id'])
260+
self.client.start(container)
261+
262+
info = self.client.inspect_container(container)
263+
container_log_config = info['HostConfig']['LogConfig']
264+
265+
self.assertEqual(container_log_config['Type'], log_config.type)
266+
self.assertEqual(container_log_config['Config'], log_config.config)
272267

273268

274269
@unittest.skipIf(not EXEC_DRIVER_IS_NATIVE, 'Exec driver not native')

0 commit comments

Comments
 (0)