-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/commonMain/kotlin/me/devnatan/yoki/util/ListAsMapToEmptyObjectsSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.devnatan.yoki.util | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.builtins.ListSerializer | ||
import kotlinx.serialization.json.JsonArray | ||
import kotlinx.serialization.json.JsonElement | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import kotlinx.serialization.json.JsonTransformingSerializer | ||
import kotlinx.serialization.json.jsonArray | ||
import kotlinx.serialization.json.jsonObject | ||
import kotlinx.serialization.json.jsonPrimitive | ||
|
||
internal open class ListAsMapToEmptyObjectsSerializer<T : Any>( | ||
private val tSerializer: KSerializer<T>, | ||
) : JsonTransformingSerializer<List<T>>(ListSerializer(tSerializer)) { | ||
|
||
override fun transformDeserialize(element: JsonElement): JsonElement { | ||
return JsonArray(element.jsonObject.entries.map { JsonPrimitive(it.key) }) | ||
} | ||
|
||
override fun transformSerialize(element: JsonElement): JsonElement { | ||
return JsonObject(element.jsonArray.associate { it.jsonPrimitive.content to JsonObject(mapOf()) }) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/commonTest/kotlin/me/devnatan/yoki/resource/container/InspectContainerIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@file:OptIn(ExperimentalCoroutinesApi::class) | ||
|
||
package me.devnatan.yoki.resource.container | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import me.devnatan.yoki.models.container.volume | ||
import me.devnatan.yoki.resource.ResourceIT | ||
import me.devnatan.yoki.withContainer | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class InspectContainerIT : ResourceIT() { | ||
|
||
@Test | ||
fun `inspects container with volumes`() = runTest { | ||
testClient.withContainer( | ||
"busybox:latest", | ||
{ | ||
volume("/opt") | ||
command = listOf("sleep", "infinity") | ||
}, | ||
) { id -> | ||
testClient.containers.start(id) | ||
try { | ||
val container = testClient.containers.inspect(id) | ||
val volumes = container.config.volumes | ||
assertEquals(volumes, listOf("/opt")) | ||
} finally { | ||
testClient.containers.stop(id) | ||
} | ||
} | ||
} | ||
} |