From b0ae88dcfb34087f588f049409bfdc2d67cdb0a5 Mon Sep 17 00:00:00 2001 From: Dai MIKURUBE Date: Thu, 8 Feb 2024 22:32:24 +0900 Subject: [PATCH] Fix environment-dependent test failures for the default ssh directory of Apache Commons VFS https://github.com/apache/commons-vfs/blob/rel/commons-vfs-2.9.0/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java#L281-L293 --- .../output/sftp/TestSftpFileOutputPlugin.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java b/src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java index d8be7d5..9a953be 100644 --- a/src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java +++ b/src/test/java/org/embulk/output/sftp/TestSftpFileOutputPlugin.java @@ -135,6 +135,9 @@ public class TestSftpFileOutputPlugin @Rule public TemporaryFolder testFolder = new TemporaryFolder(); + public String oldVfsSftpSshdir = null; + public String dotSshFolder = null; + private static final ConfigMapperFactory CONFIG_MAPPER_FACTORY = SftpFileOutputPlugin.CONFIG_MAPPER_FACTORY; private static final ConfigMapper CONFIG_MAPPER = SftpFileOutputPlugin.CONFIG_MAPPER; private static final TaskMapper TASK_MAPPER = SftpFileOutputPlugin.TASK_MAPPER; @@ -165,6 +168,10 @@ public class TestSftpFileOutputPlugin public void createResources() throws IOException { + this.dotSshFolder = testFolder.newFolder().getAbsolutePath(); + this.oldVfsSftpSshdir = System.getProperty("vfs.sftp.sshdir"); + System.setProperty("vfs.sftp.sshdir", this.dotSshFolder); + // setup the plugin SftpFileOutputPlugin sftpFileOutputPlugin = new SftpFileOutputPlugin(); runner = new FileOutputRunner(sftpFileOutputPlugin); @@ -226,6 +233,14 @@ public void cleanup() throws InterruptedException catch (Exception e) { logger.debug(e.getMessage(), e); } + finally { + if (this.oldVfsSftpSshdir == null) { + System.clearProperty("vfs.sftp.sshdir"); + } + else { + System.setProperty("vfs.sftp.sshdir", this.oldVfsSftpSshdir); + } + } } private List lsR(List fileNames, Path dir)