Skip to content

Commit c73f743

Browse files
authored
Integration test improvements (#206)
1 parent 789fb85 commit c73f743

File tree

11 files changed

+80
-76
lines changed

11 files changed

+80
-76
lines changed

api/docker-kotlin.api

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,19 +2546,18 @@ public final class me/devnatan/dockerkt/models/image/ImageRootFs$Companion {
25462546

25472547
public final class me/devnatan/dockerkt/models/image/ImageSummary {
25482548
public static final field Companion Lme/devnatan/dockerkt/models/image/ImageSummary$Companion;
2549-
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJIJLjava/util/Map;I)V
2549+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJILjava/util/Map;I)V
25502550
public final fun component1 ()Ljava/lang/String;
2551-
public final fun component10 ()I
25522551
public final fun component2 ()Ljava/lang/String;
25532552
public final fun component3 ()Ljava/util/List;
25542553
public final fun component4 ()Ljava/util/List;
25552554
public final fun component5 ()I
25562555
public final fun component6 ()J
25572556
public final fun component7 ()I
2558-
public final fun component8 ()J
2559-
public final fun component9 ()Ljava/util/Map;
2560-
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJIJLjava/util/Map;I)Lme/devnatan/dockerkt/models/image/ImageSummary;
2561-
public static synthetic fun copy$default (Lme/devnatan/dockerkt/models/image/ImageSummary;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJIJLjava/util/Map;IILjava/lang/Object;)Lme/devnatan/dockerkt/models/image/ImageSummary;
2557+
public final fun component8 ()Ljava/util/Map;
2558+
public final fun component9 ()I
2559+
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJILjava/util/Map;I)Lme/devnatan/dockerkt/models/image/ImageSummary;
2560+
public static synthetic fun copy$default (Lme/devnatan/dockerkt/models/image/ImageSummary;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Ljava/util/List;IJILjava/util/Map;IILjava/lang/Object;)Lme/devnatan/dockerkt/models/image/ImageSummary;
25622561
public fun equals (Ljava/lang/Object;)Z
25632562
public final fun getContainers ()I
25642563
public final fun getCreated ()I
@@ -2569,7 +2568,6 @@ public final class me/devnatan/dockerkt/models/image/ImageSummary {
25692568
public final fun getRepositoryTags ()Ljava/util/List;
25702569
public final fun getSharedSize ()I
25712570
public final fun getSize ()J
2572-
public final fun getVirtualSize ()J
25732571
public fun hashCode ()I
25742572
public fun toString ()Ljava/lang/String;
25752573
}

api/docker-kotlin.klib.api

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ final class me.devnatan.dockerkt.models.image/ImageRootFs { // me.devnatan.docke
15711571
}
15721572

15731573
final class me.devnatan.dockerkt.models.image/ImageSummary { // me.devnatan.dockerkt.models.image/ImageSummary|null[0]
1574-
constructor <init>(kotlin/String, kotlin/String, kotlin.collections/List<kotlin/String>, kotlin.collections/List<kotlin/String>, kotlin/Int, kotlin/Long, kotlin/Int, kotlin/Long, kotlin.collections/Map<kotlin/String, kotlin/String>?, kotlin/Int) // me.devnatan.dockerkt.models.image/ImageSummary.<init>|<init>(kotlin.String;kotlin.String;kotlin.collections.List<kotlin.String>;kotlin.collections.List<kotlin.String>;kotlin.Int;kotlin.Long;kotlin.Int;kotlin.Long;kotlin.collections.Map<kotlin.String,kotlin.String>?;kotlin.Int){}[0]
1574+
constructor <init>(kotlin/String, kotlin/String, kotlin.collections/List<kotlin/String>, kotlin.collections/List<kotlin/String>, kotlin/Int, kotlin/Long, kotlin/Int, kotlin.collections/Map<kotlin/String, kotlin/String>?, kotlin/Int) // me.devnatan.dockerkt.models.image/ImageSummary.<init>|<init>(kotlin.String;kotlin.String;kotlin.collections.List<kotlin.String>;kotlin.collections.List<kotlin.String>;kotlin.Int;kotlin.Long;kotlin.Int;kotlin.collections.Map<kotlin.String,kotlin.String>?;kotlin.Int){}[0]
15751575

15761576
final val containers // me.devnatan.dockerkt.models.image/ImageSummary.containers|{}containers[0]
15771577
final fun <get-containers>(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.containers.<get-containers>|<get-containers>(){}[0]
@@ -1591,20 +1591,17 @@ final class me.devnatan.dockerkt.models.image/ImageSummary { // me.devnatan.dock
15911591
final fun <get-sharedSize>(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.sharedSize.<get-sharedSize>|<get-sharedSize>(){}[0]
15921592
final val size // me.devnatan.dockerkt.models.image/ImageSummary.size|{}size[0]
15931593
final fun <get-size>(): kotlin/Long // me.devnatan.dockerkt.models.image/ImageSummary.size.<get-size>|<get-size>(){}[0]
1594-
final val virtualSize // me.devnatan.dockerkt.models.image/ImageSummary.virtualSize|{}virtualSize[0]
1595-
final fun <get-virtualSize>(): kotlin/Long // me.devnatan.dockerkt.models.image/ImageSummary.virtualSize.<get-virtualSize>|<get-virtualSize>(){}[0]
15961594

15971595
final fun component1(): kotlin/String // me.devnatan.dockerkt.models.image/ImageSummary.component1|component1(){}[0]
1598-
final fun component10(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.component10|component10(){}[0]
15991596
final fun component2(): kotlin/String // me.devnatan.dockerkt.models.image/ImageSummary.component2|component2(){}[0]
16001597
final fun component3(): kotlin.collections/List<kotlin/String> // me.devnatan.dockerkt.models.image/ImageSummary.component3|component3(){}[0]
16011598
final fun component4(): kotlin.collections/List<kotlin/String> // me.devnatan.dockerkt.models.image/ImageSummary.component4|component4(){}[0]
16021599
final fun component5(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.component5|component5(){}[0]
16031600
final fun component6(): kotlin/Long // me.devnatan.dockerkt.models.image/ImageSummary.component6|component6(){}[0]
16041601
final fun component7(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.component7|component7(){}[0]
1605-
final fun component8(): kotlin/Long // me.devnatan.dockerkt.models.image/ImageSummary.component8|component8(){}[0]
1606-
final fun component9(): kotlin.collections/Map<kotlin/String, kotlin/String>? // me.devnatan.dockerkt.models.image/ImageSummary.component9|component9(){}[0]
1607-
final fun copy(kotlin/String = ..., kotlin/String = ..., kotlin.collections/List<kotlin/String> = ..., kotlin.collections/List<kotlin/String> = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin.collections/Map<kotlin/String, kotlin/String>? = ..., kotlin/Int = ...): me.devnatan.dockerkt.models.image/ImageSummary // me.devnatan.dockerkt.models.image/ImageSummary.copy|copy(kotlin.String;kotlin.String;kotlin.collections.List<kotlin.String>;kotlin.collections.List<kotlin.String>;kotlin.Int;kotlin.Long;kotlin.Int;kotlin.Long;kotlin.collections.Map<kotlin.String,kotlin.String>?;kotlin.Int){}[0]
1602+
final fun component8(): kotlin.collections/Map<kotlin/String, kotlin/String>? // me.devnatan.dockerkt.models.image/ImageSummary.component8|component8(){}[0]
1603+
final fun component9(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.component9|component9(){}[0]
1604+
final fun copy(kotlin/String = ..., kotlin/String = ..., kotlin.collections/List<kotlin/String> = ..., kotlin.collections/List<kotlin/String> = ..., kotlin/Int = ..., kotlin/Long = ..., kotlin/Int = ..., kotlin.collections/Map<kotlin/String, kotlin/String>? = ..., kotlin/Int = ...): me.devnatan.dockerkt.models.image/ImageSummary // me.devnatan.dockerkt.models.image/ImageSummary.copy|copy(kotlin.String;kotlin.String;kotlin.collections.List<kotlin.String>;kotlin.collections.List<kotlin.String>;kotlin.Int;kotlin.Long;kotlin.Int;kotlin.collections.Map<kotlin.String,kotlin.String>?;kotlin.Int){}[0]
16081605
final fun equals(kotlin/Any?): kotlin/Boolean // me.devnatan.dockerkt.models.image/ImageSummary.equals|equals(kotlin.Any?){}[0]
16091606
final fun hashCode(): kotlin/Int // me.devnatan.dockerkt.models.image/ImageSummary.hashCode|hashCode(){}[0]
16101607
final fun toString(): kotlin/String // me.devnatan.dockerkt.models.image/ImageSummary.toString|toString(){}[0]

src/commonMain/kotlin/me/devnatan/dockerkt/models/image/ImageSummary.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public data class ImageSummary(
1717
@SerialName("Created") @Required public val created: Int,
1818
@SerialName("Size") @Required public val size: Long,
1919
@SerialName("SharedSize") @Required public val sharedSize: Int,
20-
@SerialName("VirtualSize") @Required public val virtualSize: Long,
2120
@SerialName("Labels") @Required public val labels: Map<String, String>?,
2221
@SerialName("Containers") @Required public val containers: Int,
2322
)

src/commonMain/kotlin/me/devnatan/dockerkt/resource/image/ImageResource.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class ImageResource internal constructor(
4141
}.execute { response ->
4242
val channel = response.body<ByteReadChannel>()
4343
while (true) {
44-
emit(json.decodeFromString(channel.readUTF8Line() ?: break))
44+
val line = channel.readUTF8Line() ?: break
45+
emit(json.decodeFromString(line))
4546
}
4647
}
4748
}

src/commonTest/kotlin/me/devnatan/dockerkt/Yoki.kt renamed to src/commonTest/kotlin/me/devnatan/dockerkt/Client.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ package me.devnatan.dockerkt
66
*/
77
fun createTestDockerClient(block: DockerClientConfigBuilder.() -> Unit = {}): DockerClient =
88
runCatching {
9-
DockerClient { apply(block) }
9+
DockerClient {
10+
debugHttpCalls(true)
11+
apply(block)
12+
}
1013
}.onFailure {
1114
@Suppress("TooGenericExceptionThrown")
1215
throw RuntimeException("Failed to initialize Docker test client", it)

src/commonTest/kotlin/me/devnatan/dockerkt/TestUtils.kt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,46 @@ suspend fun <R> DockerClient.withContainer(
3131
image: String,
3232
options: ContainerCreateOptions.() -> Unit = {},
3333
block: suspend (String) -> R,
34-
) = withImage(image) { imageTag ->
35-
try {
36-
val id =
37-
containers.create {
38-
this.image = imageTag
39-
apply(options)
34+
): Unit =
35+
withImage(image) { imageTag ->
36+
val containerId: String
37+
try {
38+
containerId =
39+
containers.create {
40+
this.image = imageTag
41+
apply(options)
42+
}
43+
} catch (e: Throwable) {
44+
fail("Failed to create container", e)
45+
}
46+
47+
try {
48+
block(containerId)
49+
} finally {
50+
containers.remove(containerId) {
51+
force = true
52+
removeAnonymousVolumes = true
4053
}
41-
block(id)
42-
containers.remove(id) {
43-
force = true
44-
removeAnonymousVolumes = true
4554
}
46-
} catch (e: Throwable) {
47-
fail("Failed to create container", e)
4855
}
49-
}
5056

5157
suspend fun <R> DockerClient.withVolume(
5258
config: VolumeCreateOptions.() -> Unit = {},
5359
block: suspend (Volume) -> R,
5460
) {
61+
val volume: Volume =
62+
try {
63+
volumes.create(config)
64+
} catch (e: Throwable) {
65+
fail("Failed to create volume", e)
66+
}
67+
5568
try {
56-
val volume = volumes.create(config)
5769
block(volume)
70+
} finally {
5871
volumes.remove(volume.name) {
5972
force = true
6073
}
61-
} catch (e: Throwable) {
62-
fail("Failed to create volume", e)
6374
}
6475
}
6576

src/commonTest/kotlin/me/devnatan/dockerkt/resource/container/StartContainerIT.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class StartContainerIT : ResourceIT() {
3232
fun `start a container with auto-assigned port bindings`() =
3333
runTest {
3434
testClient.withContainer(
35-
"busybox:latest",
35+
"nginx:latest",
3636
{
3737
exposedPort(80u)
3838
hostConfig {
@@ -41,27 +41,29 @@ class StartContainerIT : ResourceIT() {
4141
},
4242
) { id ->
4343
testClient.containers.start(id)
44-
val container = testClient.containers.inspect(id)
4544

45+
val container = testClient.containers.inspect(id)
4646
val ports = container.networkSettings.ports
47-
4847
assertTrue { ports.isNotEmpty() }
48+
4949
val exposedPort = ExposedPort(80u, ExposedPortProtocol.TCP)
50-
assertContains(ports, exposedPort)
50+
assertContains(map = ports, key = exposedPort)
5151

5252
val port80Bindings = container.networkSettings.ports[exposedPort]
5353
assertNotNull(port80Bindings)
54-
assertTrue { port80Bindings.size == 2 }
54+
assertTrue { port80Bindings.isNotEmpty() }
5555

5656
val ipv4Binding = port80Bindings[0]
5757
assertEquals(ipv4Binding.ip, "0.0.0.0")
5858
assertNotNull(ipv4Binding.port)
5959
assertTrue { ipv4Binding.port!!.toInt() > 0 }
6060

61-
val ipv6Binding = port80Bindings[1]
62-
assertEquals(ipv6Binding.ip, "::")
63-
assertNotNull(ipv6Binding.port)
64-
assertTrue { ipv6Binding.port!!.toInt() > 0 }
61+
if (port80Bindings.size > 1) {
62+
val ipv6Binding = port80Bindings[1]
63+
assertEquals(ipv6Binding.ip, "::")
64+
assertNotNull(ipv6Binding.port)
65+
assertTrue { ipv6Binding.port!!.toInt() > 0 }
66+
}
6567
}
6668
}
6769

src/commonTest/kotlin/me/devnatan/dockerkt/resource/image/PullImageIT.kt renamed to src/commonTest/kotlin/me/devnatan/dockerkt/resource/image/ImageIT.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
@file:OptIn(ExperimentalCoroutinesApi::class)
2-
31
package me.devnatan.dockerkt.resource.image
42

5-
import kotlinx.coroutines.ExperimentalCoroutinesApi
3+
import kotlinx.coroutines.flow.collect
64
import kotlinx.coroutines.test.runTest
75
import me.devnatan.dockerkt.resource.ResourceIT
86
import me.devnatan.dockerkt.withImage
97
import kotlin.test.Test
108
import kotlin.test.assertTrue
9+
import kotlin.test.fail
10+
11+
class ImageIT : ResourceIT() {
12+
@Test
13+
fun `list images`() =
14+
runTest {
15+
testClient.images.list()
16+
}
1117

12-
class PullImageIT : ResourceIT() {
1318
@Test
1419
fun `image pull`() =
1520
runTest {
@@ -20,4 +25,18 @@ class PullImageIT : ResourceIT() {
2025
)
2126
}
2227
}
28+
29+
@Test
30+
fun `image remove`() =
31+
runTest {
32+
val image = "busybox:latest"
33+
34+
try {
35+
testClient.images.pull(image).collect()
36+
} catch (e: Throwable) {
37+
fail("Failed to pull image", e)
38+
}
39+
40+
testClient.images.remove(image)
41+
}
2342
}

src/commonTest/kotlin/me/devnatan/dockerkt/resource/image/RemoveImageIT.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/commonTest/kotlin/me/devnatan/dockerkt/resource/volume/VolumeResourceIT.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class VolumeResourceIT : ResourceIT() {
4747
@Test
4848
fun `list volumes`() =
4949
runTest {
50-
val volumes = testClient.volumes.list().volumes
51-
assertTrue("Volumes must be empty, given: $volumes") { volumes.isEmpty() }
50+
testClient.volumes.list().volumes
51+
// Just expect no exception is thrown
5252
}
5353

5454
@Test
@@ -58,6 +58,7 @@ class VolumeResourceIT : ResourceIT() {
5858
testClient.volumes
5959
.list()
6060
.volumes.size
61+
6162
val newCount = 5
6263
repeat(newCount) {
6364
testClient.volumes.create()

0 commit comments

Comments
 (0)