Merge pull request #3144 from quay/move-dockerfile-parse-test

Move dockerfile parse tests to pytest
This commit is contained in:
Joseph Schorr 2018-07-13 13:18:16 +03:00 committed by GitHub
commit 823eac2a91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 66 deletions

View file

@ -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()

View 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"