Skip to content

Commit 20dc7bc

Browse files
#430: Add container initialization, run simple commant inside container and print the result of them
1 parent 0e4aadd commit 20dc7bc

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

core/jvm/test/testcontainers/TimeZoneTest.kt

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,31 @@
55

66
package testcontainers
77

8-
import kotlinx.datetime.*
8+
import org.testcontainers.junit.jupiter.Container
99
import org.testcontainers.junit.jupiter.Testcontainers
1010
import java.nio.file.Paths
11-
import java.nio.file.Files
12-
import kotlin.test.Test
13-
import kotlin.test.assertNotEquals
11+
import org.junit.jupiter.api.Test
1412

1513
@Testcontainers
1614
class TimeZoneTest {
1715

18-
@Test
19-
fun test() {
20-
val tz = TimeZone.currentSystemDefault()
21-
assertNotEquals(TimeZone.UTC, tz)
22-
println("System time zone: $tz")
16+
@Container
17+
val originalContainer = TimezoneTestContainer(
18+
Paths.get("./jvm/test/testcontainers/original/Dockerfile"),
19+
"ubuntu-arctic-longyearbyen"
20+
)
2321

24-
val filePath = Paths.get("./jvm/test/testcontainers/original/Dockerfile")
25-
val content = String(Files.readAllBytes(filePath), Charsets.UTF_8)
26-
println("Dockerfile content: \n$content")
22+
@Container
23+
val modifiedContainer = TimezoneTestContainer(
24+
Paths.get("./jvm/test/testcontainers/modified/Dockerfile"),
25+
"ubuntu-new-longyearbyen-modified"
26+
)
2727

28+
@Test
29+
fun test() {
30+
val originalExecResult = originalContainer.runTest()
31+
val modifiedExecResult = modifiedContainer.runTest()
32+
println(originalExecResult.stdout)
33+
println(modifiedExecResult.stdout)
2834
}
2935
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package testcontainers
7+
8+
import org.testcontainers.containers.Container.ExecResult
9+
import org.testcontainers.containers.GenericContainer
10+
import org.testcontainers.images.builder.ImageFromDockerfile
11+
import java.nio.file.Path
12+
13+
class TimezoneTestContainer(dockerfilePath: Path, val imageName: String) :
14+
GenericContainer<TimezoneTestContainer>(ImageFromDockerfile(imageName).withDockerfile(dockerfilePath)) {
15+
16+
init {
17+
withCommand("tail -f /dev/null")
18+
}
19+
20+
fun runTest(): ExecResult {
21+
return execInContainer("bash", "-c", "echo Inside container $imageName, system time zone: $(date -R)")
22+
}
23+
}

0 commit comments

Comments
 (0)