提交 dda00aa6 编写于 作者: J Jesse Glick

Merge pull request #1973 from jglick/TarArchiverTest.permission

Skip the test if the `tar` or `unzip` commands are not available
...@@ -32,7 +32,10 @@ import hudson.util.NullStream; ...@@ -32,7 +32,10 @@ import hudson.util.NullStream;
import hudson.util.StreamTaskListener; import hudson.util.StreamTaskListener;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Assume;
import static org.junit.Assume.*; import static org.junit.Assume.*;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -76,7 +79,7 @@ public class TarArchiverTest { ...@@ -76,7 +79,7 @@ public class TarArchiverTest {
e.mkdirs(); e.mkdirs();
// extract via the tar command // extract via the tar command
assertEquals(0, new LocalLauncher(new StreamTaskListener(System.out)).launch().cmds("tar", "xvpf", tar.getAbsolutePath()).pwd(e).join()); run(e, "tar", "xvpf", tar.getAbsolutePath());
assertEquals(0100755,e.child("a.txt").mode()); assertEquals(0100755,e.child("a.txt").mode());
assertEquals(dirMode,e.child("subdir").mode()); assertEquals(dirMode,e.child("subdir").mode());
...@@ -85,7 +88,7 @@ public class TarArchiverTest { ...@@ -85,7 +88,7 @@ public class TarArchiverTest {
// extract via the zip command // extract via the zip command
e.deleteContents(); e.deleteContents();
assertEquals(0, new LocalLauncher(new StreamTaskListener(System.out)).launch().cmds("unzip", zip.getAbsolutePath()).pwd(e).join()); run(e, "unzip", zip.getAbsolutePath());
e = e.listDirectories().get(0); e = e.listDirectories().get(0);
assertEquals(0100755, e.child("a.txt").mode()); assertEquals(0100755, e.child("a.txt").mode());
...@@ -98,6 +101,14 @@ public class TarArchiverTest { ...@@ -98,6 +101,14 @@ public class TarArchiverTest {
} }
} }
private static void run(FilePath dir, String... cmds) throws InterruptedException {
try {
assertEquals(0, new LocalLauncher(StreamTaskListener.fromStdout()).launch().cmds(cmds).pwd(dir).join());
} catch (IOException x) { // perhaps restrict to x.message.contains("Cannot run program")? or "error=2, No such file or directory"?
Assume.assumeNoException("failed to run " + Arrays.toString(cmds), x);
}
}
@Issue("JENKINS-14922") @Issue("JENKINS-14922")
@Test public void brokenSymlinks() throws Exception { @Test public void brokenSymlinks() throws Exception {
assumeTrue(!Functions.isWindows()); assumeTrue(!Functions.isWindows());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册