Skip to content

Commit

Permalink
[api] adding more tests for TarUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
siddvenk committed Nov 25, 2024
1 parent 2ceed30 commit 7c8d616
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
exclude("junit", "junit")
}
testImplementation(libs.slf4j.simple)
testImplementation(project(":testing"))
testRuntimeOnly(project(":engines:pytorch:pytorch-model-zoo"))
testRuntimeOnly(project(":engines:pytorch:pytorch-jni"))
}
Expand Down
15 changes: 15 additions & 0 deletions api/src/test/java/ai/djl/util/ZipUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package ai.djl.util;

import ai.djl.testing.TestRequirements;

import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
Expand Down Expand Up @@ -58,6 +60,19 @@ public void testOffendingTar() throws IOException {
Assert.assertTrue(Files.exists(file));
}

@Test
public void testLinuxCreatedWindowsUsedOffendingTar() throws IOException {
TestRequirements.windows();
Path tarPath = Paths.get("src/test/resources/linux-create-windows-used.tar");
Path output = Paths.get("C:/out");
Path expectedFile = output.resolve("Windows/System32/drivers/etc/dummy.txt");
Utils.deleteQuietly(expectedFile);
try (InputStream is = Files.newInputStream(tarPath)) {
TarUtils.untar(is, output, false);
}
Assert.assertTrue(Files.exists(expectedFile));
}

@Test
public void testInvalidZipFile() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions testing/src/main/java/ai/djl/testing/TestRequirements.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public static void notWindows() {
}
}

/** Requires that the test runs on windows, not OSX or linux. */
public static void windows() {
if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
throw new SkipException("This test requires windows");
}
}

/** Requires that the test runs on x86_64 arch. */
public static void notArm() {
if ("aarch64".equals(System.getProperty("os.arch"))) {
Expand Down

0 comments on commit 7c8d616

Please sign in to comment.