Skip to content

Commit e7a9ae0

Browse files
committed
Don't remove LogConfig.types shortcut
1 parent 9937a31 commit e7a9ae0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docker/utils/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, init):
2020

2121

2222
class LogConfig(DictType):
23+
types = LogConfigTypesEnum
2324

2425
def __init__(self, **kwargs):
2526
log_driver_type = kwargs.get('type', kwargs.get('Type'))

tests/utils_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,23 @@ def test_ulimit_invalid_type(self):
192192
self.assertRaises(ValueError, lambda: Ulimit(name='hello', hard='456'))
193193

194194
def test_create_host_config_dict_logconfig(self):
195-
dct = {'type': 'syslog', 'config': {'key1': 'val1'}}
195+
dct = {'type': LogConfig.types.SYSLOG, 'config': {'key1': 'val1'}}
196196
config = create_host_config(log_config=dct)
197197
self.assertIn('LogConfig', config)
198198
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
199199
self.assertEqual(dct['type'], config['LogConfig'].type)
200200

201201
def test_create_host_config_obj_logconfig(self):
202-
obj = LogConfig(type='syslog', config={'key1': 'val1'})
202+
obj = LogConfig(type=LogConfig.types.SYSLOG, config={'key1': 'val1'})
203203
config = create_host_config(log_config=obj)
204204
self.assertIn('LogConfig', config)
205205
self.assertTrue(isinstance(config['LogConfig'], LogConfig))
206206
self.assertEqual(obj, config['LogConfig'])
207207

208+
def test_logconfig_invalid_config_type(self):
209+
with pytest.raises(ValueError):
210+
LogConfig(type=LogConfig.types.JSON, config='helloworld')
211+
208212
def test_resolve_repository_name(self):
209213
# docker hub library image
210214
self.assertEqual(

0 commit comments

Comments
 (0)