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

Commit cc1b59a

Browse files
committed
Add tests for new --param argument
1 parent a09be91 commit cc1b59a

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

tests/test_dockerfile.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ def test_set_entrypoint(self):
112112
self.assertRegexpMatches(dockerfile, regex)
113113

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

@@ -128,3 +125,35 @@ def test_volumes(self):
128125
dockerfile = f.read()
129126
regex = re.compile(r'.*VOLUME \["/var/lib"\]\nVOLUME \["/usr/lib"\]', re.MULTILINE)
130127
self.assertRegexpMatches(dockerfile, regex)
128+
129+
def test_default_substitution(self):
130+
with open(self.yaml, 'ab') as f:
131+
f.write("from: {{FROM:rhel:7}}\nversion: 1.0".encode())
132+
133+
generator = Generator(self.log, self.args)
134+
generator.configure()
135+
generator.render_from_template()
136+
137+
self.assertEqual(generator.cfg['from'], 'rhel:7')
138+
139+
with open(os.path.join(self.target, "Dockerfile"), "r") as f:
140+
dockerfile = f.read()
141+
regex = re.compile(r'.*FROM rhel:7', re.MULTILINE)
142+
self.assertRegexpMatches(dockerfile, regex)
143+
144+
def test_substitution_with_parameters(self):
145+
with open(self.yaml, 'ab') as f:
146+
f.write("from: {{FROM:rhel:7}}\nversion: 1.0".encode())
147+
148+
self.args.params = {'FROM': 'centos:7'}
149+
150+
generator = Generator(self.log, self.args)
151+
generator.configure()
152+
generator.render_from_template()
153+
154+
self.assertEqual(generator.cfg['from'], 'centos:7')
155+
156+
with open(os.path.join(self.target, "Dockerfile"), "r") as f:
157+
dockerfile = f.read()
158+
regex = re.compile(r'.*FROM centos:7', re.MULTILINE)
159+
self.assertRegexpMatches(dockerfile, regex)

0 commit comments

Comments
 (0)