Move dockerfile parse tests to pytest
This commit is contained in:
parent
31bfa697f3
commit
0a23a51fba
2 changed files with 59 additions and 66 deletions
|
@ -1,66 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
|
||||
from util.dockerfileparse import parse_dockerfile
|
||||
|
||||
class TestParsedDockerfile(unittest.TestCase):
|
||||
def test_basic_parse(self):
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
self.assertEquals(("someimage", "latest"), parsed.get_image_and_tag())
|
||||
self.assertEquals("someimage", parsed.get_base_image())
|
||||
|
||||
def test_basic_parse_notag(self):
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
self.assertEquals(("someimage", "latest"), parsed.get_image_and_tag())
|
||||
self.assertEquals("someimage", parsed.get_base_image())
|
||||
|
||||
def test_two_from_lines(self):
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
FROM secondimage:second
|
||||
""")
|
||||
|
||||
self.assertEquals(("secondimage", "second"), parsed.get_image_and_tag())
|
||||
self.assertEquals("secondimage", parsed.get_base_image())
|
||||
|
||||
def test_parse_comments(self):
|
||||
parsed = parse_dockerfile("""
|
||||
# FROM someimage:latest
|
||||
FROM anotherimage:foobar # This is a comment
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
self.assertEquals(("anotherimage", "foobar"), parsed.get_image_and_tag())
|
||||
self.assertEquals("anotherimage", parsed.get_base_image())
|
||||
|
||||
def test_unicode_parse_as_ascii(self):
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
MAINTAINER José Schorr <jschorr@whatever.com>
|
||||
""")
|
||||
|
||||
self.assertEquals(("someimage", "latest"), parsed.get_image_and_tag())
|
||||
self.assertEquals("someimage", parsed.get_base_image())
|
||||
|
||||
|
||||
def test_unicode_parse_as_unicode(self):
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
MAINTAINER José Schorr <jschorr@whatever.com>
|
||||
""".decode('utf-8'))
|
||||
|
||||
self.assertEquals(("someimage", "latest"), parsed.get_image_and_tag())
|
||||
self.assertEquals("someimage", parsed.get_base_image())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
59
util/test/test_dockerfileparse.py
Normal file
59
util/test/test_dockerfileparse.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from util.dockerfileparse import parse_dockerfile
|
||||
|
||||
def test_basic_parse():
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
assert parsed.get_image_and_tag() == ("someimage", "latest")
|
||||
assert parsed.get_base_image() == "someimage"
|
||||
|
||||
def test_basic_parse_notag():
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
assert parsed.get_image_and_tag() == ("someimage", "latest")
|
||||
assert parsed.get_base_image() == "someimage"
|
||||
|
||||
def test_two_from_lines():
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
FROM secondimage:second
|
||||
""")
|
||||
|
||||
assert parsed.get_image_and_tag() == ("secondimage", "second")
|
||||
assert parsed.get_base_image() == "secondimage"
|
||||
|
||||
def test_parse_comments():
|
||||
parsed = parse_dockerfile("""
|
||||
# FROM someimage:latest
|
||||
FROM anotherimage:foobar # This is a comment
|
||||
RUN dosomething
|
||||
""")
|
||||
|
||||
assert parsed.get_image_and_tag() == ("anotherimage", "foobar")
|
||||
assert parsed.get_base_image() == "anotherimage"
|
||||
|
||||
def test_unicode_parse_as_ascii():
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
MAINTAINER José Schorr <jschorr@whatever.com>
|
||||
""")
|
||||
|
||||
assert parsed.get_image_and_tag() == ("someimage", "latest")
|
||||
assert parsed.get_base_image() == "someimage"
|
||||
|
||||
|
||||
def test_unicode_parse_as_unicode():
|
||||
parsed = parse_dockerfile("""
|
||||
FROM someimage:latest
|
||||
MAINTAINER José Schorr <jschorr@whatever.com>
|
||||
""".decode('utf-8'))
|
||||
|
||||
assert parsed.get_image_and_tag() == ("someimage", "latest")
|
||||
assert parsed.get_base_image() == "someimage"
|
Reference in a new issue