Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 0f54d7b

Browse files
committed
Merge pull request #596 from enovance/test/list_directory_with_subdir
Test/list directory with subdir
2 parents 22ff2e7 + b0ae555 commit 0f54d7b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

depends/docker-registry-core/docker_registry/drivers/dumb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def list_directory(self, path=None):
122122
ls = []
123123
for k in self._storage.keys():
124124
if (not k == path) and k.startswith(path or ''):
125-
ls.append(k)
125+
prefix = '/'
126+
if not k.startswith('/'):
127+
prefix = ''
128+
ls.append(prefix + "/".join(k.lstrip("/").split("/")[0:2]))
126129

127130
if not len(ls):
128131
raise exceptions.FileNotFoundError('%s is not there' % path)

depends/docker-registry-core/docker_registry/testing/driver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from ..core import compat
2323
from ..core import driver
2424
from ..core import exceptions
25+
from nose import SkipTest # noqa
2526
from nose import tools
2627

2728
logger = logging.getLogger(__name__)
@@ -283,6 +284,24 @@ def test_list_directory(self):
283284
assert sorted([fb1, fb2]
284285
) == sorted(list(self._storage.list_directory(base)))
285286

287+
def test_list_directory_with_subdir(self):
288+
if self.scheme == 's3':
289+
raise SkipTest("Check GH #596.")
290+
base = self.gen_random_string()
291+
dir1 = self.gen_random_string()
292+
dir2 = self.gen_random_string()
293+
filename1 = self.gen_random_string()
294+
filename2 = self.gen_random_string()
295+
fd1 = '%s/%s' % (base, dir1)
296+
fd2 = '%s/%s' % (base, dir2)
297+
fb1 = '%s/%s' % (fd1, filename1)
298+
fb2 = '%s/%s' % (fd2, filename2)
299+
content = self.gen_random_string().encode('utf8')
300+
self._storage.put_content(fb1, content)
301+
self._storage.put_content(fb2, content)
302+
assert sorted([fd1, fd2]
303+
) == sorted(list(self._storage.list_directory(base)))
304+
286305
# def test_root_list_directory(self):
287306
# fb1 = self.gen_random_string()
288307
# fb2 = self.gen_random_string()

0 commit comments

Comments
 (0)