feat: refine sftp pane upload workflow

This commit is contained in:
liumangmang
2026-04-22 17:59:07 +08:00
parent 423cca97a6
commit 165cc0e35b
10 changed files with 1188 additions and 74 deletions
@@ -1,5 +1,9 @@
package com.sshmanager.service;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import com.sshmanager.entity.Connection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -8,6 +12,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class SftpServiceTest {
@@ -48,4 +54,29 @@ class SftpServiceTest {
executorService.shutdown();
assertTrue(executorService.isTerminated() || executorService.isShutdown());
}
@Test
void statIfExistsReturnsNullWhenRemotePathIsMissing() throws Exception {
Session session = mock(Session.class);
ChannelSftp channel = mock(ChannelSftp.class);
when(channel.stat("/missing.txt")).thenThrow(new SftpException(ChannelSftp.SSH_FX_NO_SUCH_FILE, "missing"));
SftpService.PathInfo result = sftpService.statIfExists(new SftpService.SftpSession(session, channel), "/missing.txt");
assertNull(result);
}
@Test
void statIfExistsReturnsDirectoryFlagForExistingPath() throws Exception {
Session session = mock(Session.class);
ChannelSftp channel = mock(ChannelSftp.class);
SftpATTRS attrs = mock(SftpATTRS.class);
when(channel.stat("/existing")).thenReturn(attrs);
when(attrs.isDir()).thenReturn(true);
SftpService.PathInfo result = sftpService.statIfExists(new SftpService.SftpSession(session, channel), "/existing");
assertNotNull(result);
assertTrue(result.directory);
}
}