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

Commit

Permalink
Add regression tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sathlan committed Sep 23, 2014
1 parent 1b93877 commit 22066f8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
41 changes: 34 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,44 @@ 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 match the case where delimiter is "/" and
# prefix is set or the case where path is set. Good
# enough.
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
16 changes: 16 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ def test_list_directory(self):
self.setUp()
super(TestDriver, self).test_list_directory()

def test_list_directory_with_subdir(self):
base = self.gen_random_string()
dir1 = self.gen_random_string()
dir2 = self.gen_random_string()
filename1 = self.gen_random_string()
filename2 = self.gen_random_string()
fd1 = '%s/%s' % (base, dir1)
fd2 = '%s/%s' % (base, dir2)
fb1 = '%s/%s' % (fd1, filename1)
fb2 = '%s/%s' % (fd2, filename2)
content = self.gen_random_string().encode('utf8')
self._storage.put_content(fb1, content)
self._storage.put_content(fb2, content)
assert sorted([fd1, fd2]
) == sorted(list(self._storage.list_directory(base)))

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

0 comments on commit 22066f8

Please # to comment.