Skip to content

Commit 463c7b1

Browse files
committed
simplify by starting container with numeric uid to avoid the need to look it up
1 parent daf8543 commit 463c7b1

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

docker-java/src/test/java/com/github/dockerjava/cmd/CopyArchiveToContainerCmdIT.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import java.nio.file.Path;
1717
import java.nio.file.Paths;
1818
import java.util.concurrent.TimeUnit;
19-
import java.util.regex.Matcher;
20-
import java.util.regex.Pattern;
2119

2220
import static org.hamcrest.MatcherAssert.assertThat;
2321
import static org.hamcrest.Matchers.containsString;
@@ -160,11 +158,12 @@ public void copyFileWithUIDGID() throws Exception {
160158
Path without = Files.createFile(Files.createTempDirectory("copyFileWithUIDGID").resolve("uidgid.without"));
161159
Files.write(without, "with".getBytes());
162160

163-
String containerCmd = "while [ ! -f /home/uidgid.with ]; do true; done && echo uid=$(id -u) && stat -c %n:%u /home/uidgid.with /home/uidgid.without";
161+
String containerCmd = "while [ ! -f /home/uidgid.with ]; do true; done && stat -c %n:%u /home/uidgid.with /home/uidgid.without";
162+
Long syncUserUid = 4L; // sync user in busybox was uid=4
164163
CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox")
165164
.withName("copyFileWithUIDGID")
166165
.withCmd("/bin/sh", "-c", containerCmd)
167-
.withUser("sync")
166+
.withUser(syncUserUid.toString())
168167
.exec();
169168
// start the container
170169
dockerRule.getClient().startContainerCmd(container.getId()).exec();
@@ -197,12 +196,7 @@ public void copyFileWithUIDGID() throws Exception {
197196
loggingCallback.awaitCompletion(3, TimeUnit.SECONDS);
198197
String containerOutput = loggingCallback.toString();
199198

200-
Matcher uidMatcher = Pattern.compile("uid=(\\d+)").matcher(containerOutput);
201-
assertThat(String.format("cannot read effective uid on container from '%s'", containerOutput), uidMatcher.find(), equalTo(true));
202-
assertThat(String.format("cannot read effective uid on container from '%s'", containerOutput), uidMatcher.groupCount(), equalTo(1));
203-
Long containerEffectiveUid = Long.parseLong(uidMatcher.group(1));
204-
205-
assertThat(containerOutput, containsString(String.format("/home/uidgid.with:%d", containerEffectiveUid)));
199+
assertThat(containerOutput, containsString(String.format("/home/uidgid.with:%d", syncUserUid)));
206200

207201
Long hostUid = getHostUidIfPossible();
208202
assumeThat("could not get the uid on host platform", hostUid, notNullValue(Long.class));

0 commit comments

Comments
 (0)