PySshDockerContainer: simplify and document port usage

GitOrigin-RevId: 4b3a2b6cae1142ec418cb47d603e6eec35a05741
This commit is contained in:
Ilya.Kazakevich
2025-08-13 22:20:51 +00:00
committed by intellij-monorepo-bot
parent c51f227a33
commit 7373cc97bb
2 changed files with 9 additions and 3 deletions
@@ -4,7 +4,7 @@ import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
/**
* Docker container with python and ssh. Login with `user:123@127.0.0.1`
* Docker container with python and ssh. Login with `user:123@127.0.0.1:${sshContainer.sshPort}`
* ```kotlin
* @Testcontainers
* class PySshDockerTest {
@@ -15,6 +15,7 @@ import org.testcontainers.utility.DockerImageName
* }
* @Test
* fun testContainer() {
* sshContainer.sshPort // 22 ->
* }
*```
*/
@@ -23,4 +24,9 @@ class PySshDockerContainer : GenericContainer<PySshDockerContainer>(
init {
addExposedPort(22)
}
/**
* Port to connect SSH client to
*/
val sshPort: UShort get() = firstMappedPort.toUShort()
}
@@ -22,8 +22,8 @@ class PySshDockerTest {
val client = SshClient.setUpDefaultClient()
client.start()
try {
val sessionFuture = client.connect("user", InetSocketAddress("127.0.0.1", sshContainer.firstMappedPort))
Assertions.assertTrue(sessionFuture.await(10_000), "Failed to connect to ${sshContainer.firstMappedPort}")
val sessionFuture = client.connect("user", InetSocketAddress("127.0.0.1", sshContainer.sshPort.toInt()))
Assertions.assertTrue(sessionFuture.await(10_000), "Failed to connect to ${sshContainer.sshPort}")
val session = sessionFuture.session
session.addPasswordIdentity("123")
Assertions.assertTrue(session.auth().verify().isSuccess, "failed to authenticate")