Skip to content

Commit

Permalink
Update service tests to use mounts instead of volumes
Browse files Browse the repository at this point in the history
Signed-off-by: Joffrey F <[email protected]>
  • Loading branch information
shin- committed Oct 7, 2015
1 parent 37bf1b8 commit 607af35
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ def test_create_container_with_unspecified_volume(self):
service = self.create_service('db', volumes=['/var/db'])
container = service.create_container()
service.start_container(container)
self.assertIn('/var/db', container.get('Volumes'))
self.assertIsNotNone(container.get_mount('/var/db'))

def test_create_container_with_volume_driver(self):
service = self.create_service('db', volume_driver='foodriver')
container = service.create_container()
service.start_container(container)
self.assertEqual('foodriver', container.get('Config.VolumeDriver'))
self.assertEqual('foodriver', container.get('HostConfig.VolumeDriver'))

def test_create_container_with_cpu_shares(self):
service = self.create_service('db', cpu_shares=73)
Expand Down Expand Up @@ -208,12 +208,10 @@ def test_create_container_with_specified_volume(self):
service = self.create_service('db', volumes=['%s:%s' % (host_path, container_path)])
container = service.create_container()
service.start_container(container)

volumes = container.inspect()['Volumes']
self.assertIn(container_path, volumes)
self.assertIsNotNone(container.get_mount(container_path))

# Match the last component ("host-path"), because boot2docker symlinks /tmp
actual_host_path = volumes[container_path]
actual_host_path = container.get_mount(container_path)['Source']
self.assertTrue(path.basename(actual_host_path) == path.basename(host_path),
msg=("Last component differs: %s, %s" % (actual_host_path, host_path)))

Expand All @@ -224,10 +222,10 @@ def test_recreate_preserves_volume_with_trailing_slash(self):
"""
service = self.create_service('data', volumes=['/data/'])
old_container = create_and_start_container(service)
volume_path = old_container.get('Volumes')['/data']
volume_path = old_container.get_mount('/data')['Source']

new_container = service.recreate_container(old_container)
self.assertEqual(new_container.get('Volumes')['/data'], volume_path)
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)

def test_duplicate_volume_trailing_slash(self):
"""
Expand Down Expand Up @@ -295,7 +293,7 @@ def test_execute_convergence_plan_recreate(self):
self.assertEqual(old_container.name, 'composetest_db_1')
service.start_container(old_container)
old_container.inspect() # reload volume data
volume_path = old_container.get('Volumes')['/etc']
volume_path = old_container.get_mount('/etc')['Source']

num_containers_before = len(self.client.containers(all=True))

Expand All @@ -307,7 +305,7 @@ def test_execute_convergence_plan_recreate(self):
self.assertEqual(new_container.get('Config.Cmd'), ['-d', '1'])
self.assertIn('FOO=2', new_container.get('Config.Env'))
self.assertEqual(new_container.name, 'composetest_db_1')
self.assertEqual(new_container.get('Volumes')['/etc'], volume_path)
self.assertEqual(new_container.get_mount('/etc')['Source'], volume_path)
self.assertIn(
'affinity:container==%s' % old_container.id,
new_container.get('Config.Env'))
Expand Down Expand Up @@ -350,13 +348,17 @@ def test_execute_convergence_plan_with_image_declared_volume(self):
)

old_container = create_and_start_container(service)
self.assertEqual(list(old_container.get('Volumes').keys()), ['/data'])
volume_path = old_container.get('Volumes')['/data']
self.assertEqual(
[mount['Destination'] for mount in old_container.get('Mounts')], ['/data']
)
volume_path = old_container.get_mount('/data')['Source']

new_container, = service.execute_convergence_plan(
ConvergencePlan('recreate', [old_container]))
self.assertEqual(list(new_container.get('Volumes')), ['/data'])
self.assertEqual(new_container.get('Volumes')['/data'], volume_path)
self.assertEqual(
[mount['Destination'] for mount in new_container.get('Mounts')], ['/data']
)
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)

def test_start_container_passes_through_options(self):
db = self.create_service('db')
Expand Down

0 comments on commit 607af35

Please sign in to comment.