fb86b4bf2c
Fixes #423
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# -*- 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()
|
|
|