|
1 | 1 | package com.github.dockerjava.core.command; |
2 | 2 |
|
3 | | -import static org.hamcrest.MatcherAssert.assertThat; |
4 | | -import static org.hamcrest.Matchers.isEmptyString; |
5 | | -import static org.hamcrest.Matchers.not; |
6 | | - |
| 3 | +import com.github.dockerjava.api.command.CreateContainerResponse; |
| 4 | +import com.github.dockerjava.api.command.ExecCreateCmdResponse; |
| 5 | +import com.github.dockerjava.api.exception.NotFoundException; |
| 6 | +import com.github.dockerjava.client.AbstractDockerClientTest; |
7 | 7 | import java.io.InputStream; |
8 | 8 | import java.lang.reflect.Method; |
9 | 9 | import java.security.SecureRandom; |
10 | | - |
| 10 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 11 | +import static org.hamcrest.Matchers.isEmptyString; |
| 12 | +import static org.hamcrest.Matchers.not; |
11 | 13 | import org.testng.ITestResult; |
12 | 14 | import org.testng.annotations.AfterMethod; |
13 | 15 | import org.testng.annotations.AfterTest; |
14 | 16 | import org.testng.annotations.BeforeMethod; |
15 | 17 | import org.testng.annotations.BeforeTest; |
16 | 18 | import org.testng.annotations.Test; |
17 | 19 |
|
18 | | -import com.github.dockerjava.api.command.CreateContainerResponse; |
19 | | -import com.github.dockerjava.api.command.ExecCreateCmdResponse; |
20 | | -import com.github.dockerjava.client.AbstractDockerClientTest; |
21 | | - |
22 | 20 | @Test(groups = "integration") |
23 | 21 | public class ExecStartCmdImplTest extends AbstractDockerClientTest { |
24 | 22 | @BeforeTest |
@@ -53,7 +51,7 @@ public void execStart() throws Exception { |
53 | 51 | dockerClient.startContainerCmd(container.getId()).exec(); |
54 | 52 |
|
55 | 53 | ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId()) |
56 | | - .withAttachStdout(true).withCmd("touch", "/execStartTest.log").exec(); |
| 54 | + .withAttachStdout(true).withCmd("touch", "/execStartTest.log").withUser("root").exec(); |
57 | 55 | dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec( |
58 | 56 | new ExecStartResultCallback(System.out, System.err)).awaitCompletion(); |
59 | 57 |
|
@@ -92,4 +90,23 @@ public void execStartAttached() throws Exception { |
92 | 90 | assertNotNull(responseAsString); |
93 | 91 | assertTrue(responseAsString.length() > 0); |
94 | 92 | } |
| 93 | + |
| 94 | + @Test(groups = "ignoreInCircleCi", expectedExceptions = NotFoundException.class) |
| 95 | + public void execStartWithNonExistentUser() throws Exception { |
| 96 | + String containerName = "generated_" + new SecureRandom().nextInt(); |
| 97 | + |
| 98 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") |
| 99 | + .withName(containerName).exec(); |
| 100 | + LOG.info("Created container {}", container.toString()); |
| 101 | + assertThat(container.getId(), not(isEmptyString())); |
| 102 | + |
| 103 | + dockerClient.startContainerCmd(container.getId()).exec(); |
| 104 | + |
| 105 | + ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(container.getId()) |
| 106 | + .withAttachStdout(true).withCmd("touch", "/execStartTest.log").withUser("NonExistentUser").exec(); |
| 107 | + dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false).withTty(true) |
| 108 | + .exec(new ExecStartResultCallback(System.out, System.err)).awaitCompletion(); |
| 109 | + |
| 110 | + dockerClient.copyArchiveFromContainerCmd(container.getId(), "/execStartTest.log").exec(); |
| 111 | + } |
95 | 112 | } |
0 commit comments