Skip to content

Commit

Permalink
Update SftpTransportIntegrationTests.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-h-wang committed Dec 26, 2024
1 parent 508db92 commit d228e3b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.mockk.spyk
import io.mockk.unmockkAll
import net.schmizz.sshj.SSHClient
import net.schmizz.sshj.connection.ConnectionException
import net.schmizz.sshj.sftp.RemoteResourceFilter
import net.schmizz.sshj.sftp.RemoteResourceInfo
import net.schmizz.sshj.sftp.SFTPClient
import net.schmizz.sshj.transport.verification.HostKeyVerifier
Expand Down Expand Up @@ -456,10 +457,11 @@ class SftpTransportIntegrationTests : TransportIntegrationTests() {
@Test
fun `ls happy path`() {
val f = Fixture()
val nullRemoteResourceFilter: RemoteResourceFilter? = null

every { f.mockSSHClient.newSFTPClient() } returns f.mockSFTPClient
// mock a successful ls on the remote SFTP server
every { f.mockSFTPClient.ls(f.lsPath, null) } returns f.remoteResourceInfos
every { f.mockSFTPClient.ls(f.lsPath, nullRemoteResourceFilter) } returns f.remoteResourceInfos
every { f.mockSFTPClient.close() } just runs
every { f.mockSSHClient.close() } just runs
every { f.mockSSHClient.disconnect() } just runs
Expand All @@ -473,10 +475,11 @@ class SftpTransportIntegrationTests : TransportIntegrationTests() {
@Test
fun `ls connection error`() {
val f = Fixture()
val nullRemoteResourceFilter: RemoteResourceFilter? = null

every { f.mockSSHClient.newSFTPClient() } returns f.mockSFTPClient
// throw a connection exception on ls
every { f.mockSFTPClient.ls(f.lsPath, null) } throws ConnectionException("oops")
every { f.mockSFTPClient.ls(f.lsPath, nullRemoteResourceFilter) } throws ConnectionException("oops")
every { f.mockSFTPClient.close() } just runs
every { f.mockSSHClient.close() } just runs
every { f.mockSSHClient.disconnect() } just runs
Expand All @@ -490,10 +493,14 @@ class SftpTransportIntegrationTests : TransportIntegrationTests() {
@Test
fun `ls ignore timeout error`() {
val f = Fixture()
val nullRemoteResourceFilter: RemoteResourceFilter? = null

every { f.mockSSHClient.newSFTPClient() } returns f.mockSFTPClient
// throw a ConnectionException on ls with TimeoutException as a cause
every { f.mockSFTPClient.ls(f.lsPath, null) } throws ConnectionException("oops", TimeoutException())
every { f.mockSFTPClient.ls(f.lsPath, nullRemoteResourceFilter) } throws ConnectionException(
"oops",
TimeoutException()
)
every { f.mockSFTPClient.close() } just runs
every { f.mockSSHClient.close() } just runs
every { f.mockSSHClient.disconnect() } just runs
Expand Down

0 comments on commit d228e3b

Please sign in to comment.