Skip to content

Commit e6666f8

Browse files
committed
Add new unit test case for ENV substitution
1 parent 5cbefec commit e6666f8

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

src/test/java/com/github/dockerjava/client/command/BuildImageCmdTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.IOException;
1313
import java.io.StringWriter;
1414
import java.lang.reflect.Method;
15+
import java.net.URI;
16+
import java.net.URISyntaxException;
1517

1618
import org.apache.commons.io.IOUtils;
1719
import org.apache.commons.io.LineIterator;
@@ -113,6 +115,7 @@ public void testDockerBuilderAddFolder() throws DockerException,
113115
dockerfileBuild(baseDir, "Successfully executed testAddFolder.sh");
114116
}
115117

118+
116119
private String dockerfileBuild(File baseDir, String expectedText)
117120
throws DockerException, IOException {
118121

@@ -222,4 +225,12 @@ public void testNetCatDockerfileBuilder() throws DockerException,
222225
dockerClient.stopContainerCmd(container.getId()).withTimeout(0).exec();
223226

224227
}
228+
229+
@Test
230+
public void testAddAndCopySubstitution () throws DockerException, IOException {
231+
File baseDir = new File(Thread.currentThread().getContextClassLoader()
232+
.getResource("testENVSubstitution").getFile());
233+
dockerfileBuild(baseDir, "Successfully executed testAddFolder.sh");
234+
235+
}
225236
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ubuntu
2+
3+
# Copy testrun.sh files into the container
4+
5+
ENV variable abc123
6+
ADD ./testrun.sh /tmp/
7+
ADD ./subst-file-$variable.txt /tmp/
8+
COPY ./subst-file-2-${variable}.txt /tmp/
9+
RUN cp /tmp/testrun.sh /usr/local/bin/ && chmod +x /usr/local/bin/testrun.sh
10+
11+
CMD ["testrun.sh"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Old File
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Old File
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
echo "Hello Word" > hello.txt
4+
echo "hello.txt Created"
5+
6+
TEST_FILE=/tmp/subst-file-abc123.txt
7+
TEST_FILE_2=/tmp/subst-file-2-abc123.txt
8+
9+
if test -f $TEST_FILE
10+
then
11+
12+
if test -f $TEST_FILE_2
13+
then
14+
exit 0
15+
else
16+
echo "$TEST_FILE_2 does not exist"
17+
exit 1
18+
fi
19+
20+
else
21+
22+
echo "$TEST_FILE does not exist"
23+
exit 1
24+
25+
fi
26+

0 commit comments

Comments
 (0)