Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
to check whether loading `.so` or `.dylib` from `java.library.path` works, when not calling `FuseBuilder.setLibraryPath(...)`
  • Loading branch information
overheadhunter committed Sep 27, 2023
1 parent 40a812f commit 0a8a238
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.cryptomator.jfuse.tests;

import org.cryptomator.jfuse.api.Fuse;
import org.cryptomator.jfuse.examples.RandomFileSystem;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeoutException;

@EnabledIfSystemProperty(named = "fuse.lib.path", matches = ".+")
public class FallbackLibLoadingIT {

@Test
@EnabledOnOs(OS.LINUX)
@DisplayName("loads fuse lib from java.library.path, if not calling FuseBuilder.setLibraryPath(...)")
public void loadFromJavaLibraryPathOnLinux(@TempDir Path p) throws IOException, TimeoutException {
loadFromJavaLibraryPath(p, "libfuse3.so");
}

@Test
@EnabledOnOs(OS.MAC)
@DisplayName("loads fuse lib from java.library.path, if not calling FuseBuilder.setLibraryPath(...)")
public void loadFromJavaLibraryPathOnMacOS(@TempDir Path p) throws IOException, TimeoutException {
loadFromJavaLibraryPath(p, "libfuse-t.dylib");
}

private void loadFromJavaLibraryPath(Path tmpLibPath, String libFileName) throws IOException, TimeoutException {
var libPath = System.getProperty("fuse.lib.path");
var symlinkPath = tmpLibPath.resolve(libFileName);
Files.createSymbolicLink(symlinkPath, Path.of(libPath));

System.setProperty("java.library.path", tmpLibPath.toString());

var builder = Fuse.builder();
var fs = new RandomFileSystem(builder.errno());
var fuse = Assertions.assertDoesNotThrow(() -> builder.build(fs));
fuse.close();
}

}

0 comments on commit 0a8a238

Please sign in to comment.