Răsfoiți Sursa

Fix `config` command to print the new sections of the config

Signed-off-by: Daniel Nephin <[email protected]>
Daniel Nephin 9 ani în urmă
părinte
comite
3021ee12fe

+ 1 - 1
compose/cli/main.py

@@ -217,7 +217,7 @@ class TopLevelCommand(DocoptCommand):
 
         compose_config = dict(
             (service.pop('name'), service) for service in compose_config.services)
-        print(yaml.dump(
+        print(yaml.safe_dump(
             compose_config,
             default_flow_style=False,
             indent=2,

+ 25 - 12
tests/acceptance/cli_test.py

@@ -10,8 +10,8 @@ import subprocess
 import time
 from collections import namedtuple
 from operator import attrgetter
-from textwrap import dedent
 
+import yaml
 from docker import errors
 
 from .. import mock
@@ -148,8 +148,9 @@ class CLITestCase(DockerClientTestCase):
         self.base_dir = None
 
     def test_config_list_services(self):
+        self.base_dir = 'tests/fixtures/v2-full'
         result = self.dispatch(['config', '--services'])
-        assert set(result.stdout.rstrip().split('\n')) == {'simple', 'another'}
+        assert set(result.stdout.rstrip().split('\n')) == {'web', 'other'}
 
     def test_config_quiet_with_error(self):
         self.base_dir = None
@@ -160,20 +161,32 @@ class CLITestCase(DockerClientTestCase):
         assert "'notaservice' doesn't have any configuration" in result.stderr
 
     def test_config_quiet(self):
+        self.base_dir = 'tests/fixtures/v2-full'
         assert self.dispatch(['config', '-q']).stdout == ''
 
     def test_config_default(self):
+        self.base_dir = 'tests/fixtures/v2-full'
         result = self.dispatch(['config'])
-        assert dedent("""
-            simple:
-              command: top
-              image: busybox:latest
-        """).lstrip() in result.stdout
-        assert dedent("""
-            another:
-              command: top
-              image: busybox:latest
-        """).lstrip() in result.stdout
+        # assert there are no python objects encoded in the output
+        assert '!!' not in result.stdout
+
+        output = yaml.load(result.stdout)
+        expected = {
+            'version': 2,
+            'volumes': {'data': {'driver': 'local'}},
+            'networks': {'front': {}},
+            'services': {
+                'web': {
+                    'build': os.path.abspath(self.base_dir),
+                    'networks': ['front', 'default'],
+                },
+                'other': {
+                    'image': 'busybox:latest',
+                    'command': 'top',
+                },
+            },
+        }
+        assert output == expected
 
     def test_ps(self):
         self.project.get_service('simple').create_container()

+ 4 - 0
tests/fixtures/v2-full/docker-compose.yml

@@ -14,7 +14,11 @@ services:
     networks:
       - front
       - default
+    volumes_from:
+      - other
 
   other:
     image: busybox:latest
     command: top
+    volumes:
+      - /data