mirror of
https://github.com/docker/compose.git
synced 2025-07-27 15:44:08 +02:00
Reduce config --hash code complexity and add test
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
707e21183f
commit
861031b9b7
@ -328,8 +328,9 @@ class TopLevelCommand(object):
|
|||||||
anything.
|
anything.
|
||||||
--services Print the service names, one per line.
|
--services Print the service names, one per line.
|
||||||
--volumes Print the volume names, one per line.
|
--volumes Print the volume names, one per line.
|
||||||
--hash="all" Print the service config hash, one per line.
|
--hash="*" Print the service config hash, one per line.
|
||||||
Set "service1,service2" for a list of specified services.
|
Set "service1,service2" for a list of specified services
|
||||||
|
or use the wildcard symbol to display all services
|
||||||
"""
|
"""
|
||||||
|
|
||||||
compose_config = get_config_from_options(self.project_dir, self.toplevel_options)
|
compose_config = get_config_from_options(self.project_dir, self.toplevel_options)
|
||||||
@ -352,17 +353,12 @@ class TopLevelCommand(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if options['--hash'] is not None:
|
if options['--hash'] is not None:
|
||||||
|
h = options['--hash']
|
||||||
self.project = project_from_options('.', self.toplevel_options)
|
self.project = project_from_options('.', self.toplevel_options)
|
||||||
if options['--hash'] == "all":
|
services = [svc for svc in options['--hash'].split(',')] if h != '*' else None
|
||||||
for service in self.project.services:
|
|
||||||
|
for service in self.project.get_services(services):
|
||||||
print('{} {}'.format(service.name, service.config_hash))
|
print('{} {}'.format(service.name, service.config_hash))
|
||||||
else:
|
|
||||||
for service_name in options['--hash'].split(','):
|
|
||||||
try:
|
|
||||||
print('{} {}'.format(service_name,
|
|
||||||
self.project.get_service(service_name).config_hash))
|
|
||||||
except NoSuchService as s:
|
|
||||||
print('{}'.format(s))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
print(serialize_config(compose_config, image_digests))
|
print(serialize_config(compose_config, image_digests))
|
||||||
|
@ -222,6 +222,17 @@ class CLITestCase(DockerClientTestCase):
|
|||||||
self.base_dir = 'tests/fixtures/v2-full'
|
self.base_dir = 'tests/fixtures/v2-full'
|
||||||
assert self.dispatch(['config', '--quiet']).stdout == ''
|
assert self.dispatch(['config', '--quiet']).stdout == ''
|
||||||
|
|
||||||
|
def test_config_with_hash_option(self):
|
||||||
|
self.base_dir = 'tests/fixtures/v2-full'
|
||||||
|
self.project.build()
|
||||||
|
result = self.dispatch(['config', '--hash=*'])
|
||||||
|
for service in self.project.get_services():
|
||||||
|
assert '{} {}\n'.format(service.name, service.config_hash) in result.stdout
|
||||||
|
|
||||||
|
svc = self.project.get_service('other')
|
||||||
|
result = self.dispatch(['config', '--hash=other'])
|
||||||
|
assert result.stdout == '{} {}\n'.format(svc.name, svc.config_hash)
|
||||||
|
|
||||||
def test_config_default(self):
|
def test_config_default(self):
|
||||||
self.base_dir = 'tests/fixtures/v2-full'
|
self.base_dir = 'tests/fixtures/v2-full'
|
||||||
result = self.dispatch(['config'])
|
result = self.dispatch(['config'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user