|
3 | 3 | import static org.hamcrest.MatcherAssert.assertThat; |
4 | 4 | import static org.hamcrest.Matchers.isEmptyOrNullString; |
5 | 5 | import static org.hamcrest.Matchers.not; |
| 6 | +import static org.hamcrest.Matchers.equalTo; |
6 | 7 |
|
7 | 8 | import java.io.IOException; |
8 | 9 | import java.io.InputStream; |
@@ -117,5 +118,39 @@ public void copyDirWithLastAddedTarEnryEmptyDir() throws Exception{ |
117 | 118 | .withHostResource(localDir.toString()) |
118 | 119 | .exec(); |
119 | 120 | } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void copyFileWithExecutePermission() throws Exception { |
| 124 | + // create script file, add permission to execute |
| 125 | + scriptPath = Files.createTempFile("run", ".sh"); |
| 126 | + boolean executable = scriptPath.toFile().setExecutable(true, false); |
| 127 | + if (!executable){ |
| 128 | + throw new Exception("Execute permission on file not set!"); |
| 129 | + } |
| 130 | + String snippet = "Running script with execute permission."; |
| 131 | + String scriptTextStr = "#!/bin/sh\necho \"" + snippet + "\""; |
| 132 | + // write content for created script |
| 133 | + Files.write(scriptPath, scriptTextStr.getBytes()); |
| 134 | + // create a test container which starts and waits 3 seconds for the |
| 135 | + // script to be copied to the container's home dir and then executes it |
| 136 | + String containerCmd = "sleep 3; /home/" + scriptPath.getFileName().toString(); |
| 137 | + CreateContainerResponse container = docker.createContainerCmd("busybox") |
| 138 | + .withName("test") |
| 139 | + .withCmd("/bin/sh", "-c", containerCmd) |
| 140 | + .exec(); |
| 141 | + // start the container |
| 142 | + docker.startContainerCmd(container.getId()).exec(); |
| 143 | + // copy script to container home dir |
| 144 | + docker.copyArchiveToContainerCmd(container.getId()) |
| 145 | + .withRemotePath("/home") |
| 146 | + .withHostResource(scriptPath.toString()) |
| 147 | + .exec(); |
| 148 | + // await exid code |
| 149 | + int exitCode = docker.waitContainerCmd(container.getId()) |
| 150 | + .exec(new WaitContainerResultCallback()) |
| 151 | + .awaitStatusCode(); |
| 152 | + // check result |
| 153 | + assertThat(exitCode, equalTo(0)); |
| 154 | + } |
120 | 155 |
|
121 | 156 | } |
0 commit comments