Skip to content

Commit

Permalink
Revert unnecessary changes to minimize diff
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Oct 15, 2024
1 parent 2cf54e6 commit 45d34c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
25 changes: 11 additions & 14 deletions core/src/test/java/hudson/util/io/TarArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,21 @@ private static void run(FilePath dir, String... cmds) throws InterruptedExceptio
public void emptyDirectory() throws Exception {
Path tar = tmp.newFile("test.tar").toPath();
Path root = tmp.newFolder().toPath();
Files.createDirectory(root.resolve("a"));
Files.createDirectory(root.resolve("b"));

Files.writeString(root.resolve("a/file.txt"), "empty_dir_test");

try (OutputStream outputStream = Files.newOutputStream(tar)) {
new FilePath(root.toFile()).tar(outputStream, "**");
Files.createDirectory(root.resolve("foo"));
Files.createDirectory(root.resolve("bar"));
Files.writeString(root.resolve("bar/file.txt"), "foobar", StandardCharsets.UTF_8);
try (OutputStream out = Files.newOutputStream(tar)) {
new FilePath(root.toFile()).tar(out, "**");
}

Set<String> names = new HashSet<>();
try (InputStream inputStream = Files.newInputStream(tar);
TarInputStream tarInputStream = new TarInputStream(inputStream, StandardCharsets.UTF_8.name())) {
TarEntry tarEntry;
while ((tarEntry = tarInputStream.getNextEntry()) != null) {
names.add(tarEntry.getName());
try (InputStream is = Files.newInputStream(tar);
TarInputStream tis = new TarInputStream(is, StandardCharsets.UTF_8.name())) {
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
names.add(te.getName());
}
}
assertEquals(Set.of("a/", "b/", "a/file.txt"), names);
assertEquals(Set.of("foo/", "bar/", "bar/file.txt"), names);
}

/**
Expand Down
24 changes: 11 additions & 13 deletions core/src/test/java/hudson/util/io/ZipArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

public class ZipArchiverTest {

@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@Rule public TemporaryFolder tmp = new TemporaryFolder();

@Issue("JENKINS-9942")
@Test
Expand Down Expand Up @@ -86,21 +85,20 @@ public void huge64bitFile() throws IOException {
public void emptyDirectory() throws Exception {
Path zip = tmp.newFile("test.zip").toPath();
Path root = tmp.newFolder().toPath();
Files.createDirectory(root.resolve("a"));
Files.createDirectory(root.resolve("b"));
Files.writeString(root.resolve("a/file.txt"), "empty_dir_zip_test");
Files.createDirectory(root.resolve("foo"));
Files.createDirectory(root.resolve("bar"));
Files.writeString(root.resolve("bar/file.txt"), "foobar", StandardCharsets.UTF_8);
try (OutputStream out = Files.newOutputStream(zip)) {
new FilePath(root.toFile()).zip(out, "**");
}
Set<String> actual = new HashSet<>();
Set<String> expected = Set.of("a/", "b/", "a/file.txt");
try (InputStream inputStream = Files.newInputStream(zip);
ZipInputStream zipInputStream = new ZipInputStream(inputStream, StandardCharsets.UTF_8)) {
ZipEntry zipEntry;
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
actual.add(zipEntry.getName());
Set<String> names = new HashSet<>();
try (InputStream is = Files.newInputStream(zip);
ZipInputStream zis = new ZipInputStream(is, StandardCharsets.UTF_8)) {
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
names.add(ze.getName());
}
}
assertEquals(expected, actual);
assertEquals(Set.of("foo/", "bar/", "bar/file.txt"), names);
}
}

0 comments on commit 45d34c6

Please sign in to comment.