mirror of https://github.com/docker/docker-py.git
Merge pull request #180 from StarvingMarvin/parse_repository_tag
parse_repository_tag function and accompanying test
This commit is contained in:
commit
24cc9df5f5
|
@ -1,3 +1,3 @@
|
|||
from .utils import (
|
||||
compare_version, convert_port_bindings, mkbuildcontext, ping, tar
|
||||
compare_version, convert_port_bindings, mkbuildcontext, ping, tar, parse_repository_tag
|
||||
) # flake8: noqa
|
||||
|
|
|
@ -114,3 +114,15 @@ def convert_port_bindings(port_bindings):
|
|||
else:
|
||||
result[key] = [_convert_port_binding(v)]
|
||||
return result
|
||||
|
||||
|
||||
def parse_repository_tag(repo):
|
||||
column_index = repo.rfind(':')
|
||||
if column_index < 0:
|
||||
return repo, ""
|
||||
tag = repo[column_index+1:]
|
||||
slash_index = tag.find('/')
|
||||
if slash_index < 0:
|
||||
return repo[:column_index], tag
|
||||
|
||||
return repo, ""
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import unittest
|
||||
|
||||
from docker.utils import parse_repository_tag
|
||||
|
||||
|
||||
class UtilsTest(unittest.TestCase):
|
||||
|
||||
def test_parse_repository_tag(self):
|
||||
self.assertEqual(parse_repository_tag("root"),
|
||||
("root", ""))
|
||||
self.assertEqual(parse_repository_tag("root:tag"),
|
||||
("root", "tag"))
|
||||
self.assertEqual(parse_repository_tag("user/repo"),
|
||||
("user/repo", ""))
|
||||
self.assertEqual(parse_repository_tag("user/repo:tag"),
|
||||
("user/repo", "tag"))
|
||||
self.assertEqual(parse_repository_tag("url:5000/repo"),
|
||||
("url:5000/repo", ""))
|
||||
self.assertEqual(parse_repository_tag("url:5000/repo:tag"),
|
||||
("url:5000/repo", "tag"))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue