Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
Add non regression tests for the subdir case.
Browse files Browse the repository at this point in the history
  • Loading branch information
sathlan committed Oct 16, 2014
1 parent 1b93877 commit 44148d8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
39 changes: 32 additions & 7 deletions tests/mocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'''Monkeypatch Openstack Swift Client for testing'''

import swiftclient
import re

from docker_registry.testing.utils import monkeypatch_class

Expand All @@ -28,18 +29,42 @@ def delete_container(self, container, response_dict=None):
self._swift_containers.pop(container, None)

''' Get a listing of objects for the container. '''
# The behaviour of the swift listdir client is very subtle. Given
# the prefix, delimiter and path combo, a lot of different type of
# listing is possible. Try to mimic this behaviour as close as
# possible.
def get_container(self, container, marker=None, limit=None, prefix=None,
delimiter=None, end_marker=None, path=None,
full_listing=False):
lst = []
if path is None:
if prefix[-1] != '/':
path = prefix + '/'
else:
path = prefix
search = path
if search is None:
search = prefix
# The case which are not handled at all here is when the
# prefix does not end with a slash (which is equivalent to ls
# -d). The list_directory function ensure that is not the
# case, so there is no need.
for key, value in self._swift_containers[container].iteritems():
if key.startswith(path):
lst.append({'name': key})
# works only for two level deep path. Enough to test.
if delimiter is None and prefix is not None:
# This output all the files matching the prefix,
# regardless of how deep they are.
path_re = re.compile("(%s/?)(.+)?$" % search)
else:
# this split the a two level path
path_re = re.compile("(%s/?)([^/]+)(/.*)?$" % search)
match = path_re.match(key)
if match is not None:
if match.group(3) is not None:
# we have a subdir
hash_key = 'subdir'
suffix = '/'
else:
# we have a file
hash_key = 'name'
suffix = ''
found_file = match.group(1) + match.group(2) + suffix
lst.append({hash_key: found_file})
return None, lst

''' attempt to retrieve metadata about an object within a container '''
Expand Down
10 changes: 10 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def test_list_directory(self):
self.setUp()
super(TestDriver, self).test_list_directory()

def test_list_directory_with_subdir(self):
# Test with root directory
super(TestDriver, self).test_list_directory_with_subdir()
self.tearDown()

# Test with custom root directory
self.config = testing.Config({'storage_path': '/foo'})
self.setUp()
super(TestDriver, self).test_list_directory_with_subdir()

def test_swift_root_path_default(self):
assert self._storage._root_path == '/'
assert self._storage._init_path() == ''
Expand Down

0 comments on commit 44148d8

Please # to comment.