Skip to content

Commit 7b3763f

Browse files
kpelykhzettaset-kpelykh
authored andcommitted
fixed all the tests
1 parent 3761f1a commit 7b3763f

3 files changed

Lines changed: 19 additions & 33 deletions

File tree

src/main/java/com/kpelykh/docker/client/DockerClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,20 +643,20 @@ public ClientResponse build(File dockerFolder, String tag) throws DockerExceptio
643643
FileUtils.copyFileToDirectory(dockerFile, tmpDockerContextFolder);
644644

645645
for (String cmd : dockerFileContent) {
646-
if (StringUtils.startsWith(cmd.trim(), "ADD")) {
646+
if (StringUtils.startsWithIgnoreCase(cmd.trim(), "ADD")) {
647647
String addArgs[] = StringUtils.split(cmd, " \t");
648648
if (addArgs.length != 3) {
649649
throw new DockerException(String.format("Wrong format on line [%s]", cmd));
650650
}
651651

652652
File src = new File(addArgs[1]);
653-
/* if (!src.isAbsolute()) {
654-
src = new File(dockerFolder, addArgs[1]).getCanonicalFile();
653+
if (!src.isAbsolute()) {
654+
src = new File(dockerFolder, addArgs[1]).getCanonicalFile();
655655
}
656656

657657
if (!src.exists()) {
658-
throw new DockerException(String.format("Sorce file %s doesnt' exist", src));
659-
}*/
658+
throw new DockerException(String.format("Source file %s doesnt' exist", src));
659+
}
660660
if (src.isDirectory()) {
661661
FileUtils.copyDirectory(src, tmpDockerContextFolder);
662662
} else {

src/main/java/com/kpelykh/docker/client/model/Ports.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.codehaus.jackson.map.SerializerProvider;
88
import org.codehaus.jackson.map.annotate.JsonDeserialize;
99
import org.codehaus.jackson.map.annotate.JsonSerialize;
10+
import org.codehaus.jackson.node.NullNode;
1011

1112
import java.io.IOException;
1213
import java.util.HashMap;
@@ -95,10 +96,11 @@ public Ports deserialize(JsonParser jsonParser, DeserializationContext deseriali
9596
for (Iterator<Map.Entry<String, JsonNode>> it = node.getFields(); it.hasNext();) {
9697

9798
Map.Entry<String, JsonNode> field = it.next();
98-
String hostIp = field.getValue().get(0).get("HostIp").getTextValue();
99-
String hostPort = field.getValue().get(0).get("HostPort").getTextValue();
100-
out.addPort(Port.makePort(field.getKey(), hostIp, hostPort));
101-
99+
if (!field.getValue().equals(NullNode.getInstance())) {
100+
String hostIp = field.getValue().get(0).get("HostIp").getTextValue();
101+
String hostPort = field.getValue().get(0).get("HostPort").getTextValue();
102+
out.addPort(Port.makePort(field.getKey(), hostIp, hostPort));
103+
}
102104
}
103105
return out;
104106
}

src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,6 @@ public void testStartContainer() throws DockerException {
244244

245245
}
246246

247-
/* @Test
248-
public void testStartContainer2() throws DockerException {ContainerConfig appContainerConfig = new ContainerConfig();
249-
appContainerConfig.setImage("4096e911ada1");
250-
ContainerCreateResponse appContResponse = dockerClient.createContainer(appContainerConfig, "AppContainer");
251-
System.out.println("Created an App container successfully: " + appContResponse.getId());
252-
String appContId = appContResponse.getId();
253-
HostConfig appHostConfig = new HostConfig(null);
254-
Port p = new Port("tcp","8080","0.0.0.0","8082");
255-
Ports ports = new Ports();
256-
ports.addPort(p);
257-
appHostConfig.setPortBindings(ports);
258-
String[] links = {"mariaDB3:db"};
259-
appHostConfig.setLinks(links);
260-
dockerClient.startContainer(appContId, appHostConfig);
261-
}
262-
*/
263247
@Test
264248
public void testWaitContainer() throws DockerException {
265249

@@ -601,7 +585,7 @@ public void testRunShlex() throws DockerException {
601585
}
602586

603587

604-
@Test(enabled = false)
588+
@Test
605589
public void testNginxDockerfileBuilder() throws DockerException, IOException {
606590
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("nginx").getFile());
607591

@@ -623,7 +607,7 @@ public void testNginxDockerfileBuilder() throws DockerException, IOException {
623607
String fullLog = logwriter.toString();
624608
assertThat(fullLog, containsString("Successfully built"));
625609

626-
String imageId = StringUtils.substringAfterLast(fullLog, "Successfully built ").trim();
610+
String imageId = StringUtils.substringBetween(fullLog, "Successfully built ", "\\n\"}").trim();
627611

628612
ImageInspectResponse imageInspectResponse = dockerClient.inspectImage(imageId);
629613
assertThat(imageInspectResponse, not(nullValue()));
@@ -633,19 +617,19 @@ public void testNginxDockerfileBuilder() throws DockerException, IOException {
633617
assertThat(imageInspectResponse.getAuthor(), equalTo("Guillaume J. Charmes \"[email protected]\""));
634618
}
635619

636-
@Test(enabled = false)
620+
@Test
637621
public void testDockerBuilderAddFile() throws DockerException, IOException {
638622
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testAddFile").getFile());
639623
dockerfileBuild(baseDir, "Successfully executed testrun.sh");
640624
}
641625

642-
@Test(enabled = false)
626+
@Test
643627
public void testDockerBuilderAddFolder() throws DockerException, IOException {
644628
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testAddFolder").getFile());
645629
dockerfileBuild(baseDir, "Successfully executed testAddFolder.sh");
646630
}
647631

648-
@Test(enabled = false)
632+
@Test
649633
public void testNetCatDockerfileBuilder() throws DockerException, IOException, InterruptedException {
650634
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("netcat").getFile());
651635

@@ -667,7 +651,7 @@ public void testNetCatDockerfileBuilder() throws DockerException, IOException, I
667651
String fullLog = logwriter.toString();
668652
assertThat(fullLog, containsString("Successfully built"));
669653

670-
String imageId = StringUtils.substringAfterLast(fullLog, "Successfully built ").trim();
654+
String imageId = StringUtils.substringBetween(fullLog, "Successfully built ", "\\n\"}").trim();
671655

672656
ImageInspectResponse imageInspectResponse = dockerClient.inspectImage(imageId);
673657
assertThat(imageInspectResponse, not(nullValue()));
@@ -758,7 +742,7 @@ private void dockerfileBuild(File baseDir, String expectedText) throws DockerExc
758742
String fullLog = logwriter.toString();
759743
assertThat(fullLog, containsString("Successfully built"));
760744

761-
String imageId = StringUtils.substringAfterLast(fullLog, "Successfully built ").trim();
745+
String imageId = StringUtils.substringBetween(fullLog, "Successfully built ", "\\n\"}").trim();
762746

763747
//Create container based on image
764748
ContainerConfig containerConfig = new ContainerConfig();
@@ -788,6 +772,6 @@ private void dockerfileBuild(File baseDir, String expectedText) throws DockerExc
788772
IOUtils.closeQuietly(logResponse.getEntityInputStream());
789773
}
790774

791-
assertThat(logwriter2.toString(), equalTo(expectedText));
775+
assertThat(logwriter2.toString(), endsWith(expectedText));
792776
}
793777
}

0 commit comments

Comments
 (0)