Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Add tests for new --param argument
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmann committed May 2, 2017
1 parent a09be91 commit cc1b59a
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tests/test_dockerfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ def test_set_entrypoint(self):
self.assertRegexpMatches(dockerfile, regex)

def test_volumes(self):
"""
Test that cmd: is mapped into a CMD instruction
"""
with open(self.yaml, 'ab') as f:
f.write("volumes:\n - '/var/lib'\n - '/usr/lib'".encode())

Expand All @@ -128,3 +125,35 @@ def test_volumes(self):
dockerfile = f.read()
regex = re.compile(r'.*VOLUME \["/var/lib"\]\nVOLUME \["/usr/lib"\]', re.MULTILINE)
self.assertRegexpMatches(dockerfile, regex)

def test_default_substitution(self):
with open(self.yaml, 'ab') as f:
f.write("from: {{FROM:rhel:7}}\nversion: 1.0".encode())

generator = Generator(self.log, self.args)
generator.configure()
generator.render_from_template()

self.assertEqual(generator.cfg['from'], 'rhel:7')

with open(os.path.join(self.target, "Dockerfile"), "r") as f:
dockerfile = f.read()
regex = re.compile(r'.*FROM rhel:7', re.MULTILINE)
self.assertRegexpMatches(dockerfile, regex)

def test_substitution_with_parameters(self):
with open(self.yaml, 'ab') as f:
f.write("from: {{FROM:rhel:7}}\nversion: 1.0".encode())

self.args.params = {'FROM': 'centos:7'}

generator = Generator(self.log, self.args)
generator.configure()
generator.render_from_template()

self.assertEqual(generator.cfg['from'], 'centos:7')

with open(os.path.join(self.target, "Dockerfile"), "r") as f:
dockerfile = f.read()
regex = re.compile(r'.*FROM centos:7', re.MULTILINE)
self.assertRegexpMatches(dockerfile, regex)

0 comments on commit cc1b59a

Please sign in to comment.