From dc064446bfbd8253a72c1062c3bb15317f2be0f8 Mon Sep 17 00:00:00 2001 From: BDA <58807088+boddissattva@users.noreply.github.com> Date: Tue, 19 Mar 2024 09:44:48 +0100 Subject: [PATCH] chore(): Allow build with TestContainers' test for kotlin-dsl on docker in WSL2 without desktop (#37) --- .../test/kotlin/blackbox/IntegrationTest.kt | 11 +++-- .../dsl/src/test/kotlin/util/WSLUtil.kt | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 kotlin-dsl/dsl/src/test/kotlin/util/WSLUtil.kt diff --git a/kotlin-dsl/dsl/src/test/kotlin/blackbox/IntegrationTest.kt b/kotlin-dsl/dsl/src/test/kotlin/blackbox/IntegrationTest.kt index fbabb805a..1f2600f5d 100644 --- a/kotlin-dsl/dsl/src/test/kotlin/blackbox/IntegrationTest.kt +++ b/kotlin-dsl/dsl/src/test/kotlin/blackbox/IntegrationTest.kt @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test import org.testcontainers.containers.BindMode import org.testcontainers.containers.GenericContainer import org.testcontainers.junit.jupiter.Testcontainers +import util.WSLUtil import java.io.File import java.nio.file.Files @@ -16,14 +17,14 @@ import java.nio.file.Files class IntegrationTest { companion object { - var chutneyServer: GenericContainer? = null + private var chutneyServer: GenericContainer? = null var adminServerInfo: ChutneyServerInfo? = null var userServerInfo: ChutneyServerInfo? = null @JvmStatic @BeforeAll fun setUp() { - val tempDirectory = Files.createTempDirectory("chutney-kotlin-blackbox") + val tempDirectory = Files.createTempDirectory("chutney-kotlin-blackbox-") val memAuthConfigFile = File( IntegrationTest::class.java.getResource("/blackbox/application-mem-auth.yml")!!.path ) @@ -36,13 +37,13 @@ class IntegrationTest { .apply { //withStartupTimeout(Duration.ofSeconds(30)) withExposedPorts(8443) - withFileSystemBind(tempDirectory.toString(), "/config", BindMode.READ_WRITE) + withFileSystemBind(WSLUtil.wslPath(tempDirectory), "/config", BindMode.READ_WRITE) } chutneyServer!!.start() adminServerInfo = - ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "admin", "admin") + ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "admin", "admin", null, null, null) userServerInfo = - ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "user", "user") + ChutneyServerInfo("https://${chutneyServer?.host}:${chutneyServer?.firstMappedPort}", "user", "user", null, null, null) // Set authorizations val roles = IntegrationTest::class.java.getResource("/blackbox/roles.json")!!.path diff --git a/kotlin-dsl/dsl/src/test/kotlin/util/WSLUtil.kt b/kotlin-dsl/dsl/src/test/kotlin/util/WSLUtil.kt new file mode 100644 index 000000000..b0c5410c0 --- /dev/null +++ b/kotlin-dsl/dsl/src/test/kotlin/util/WSLUtil.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2017-2023 Enedis + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package util + +import org.apache.commons.lang3.SystemUtils +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.condition.EnabledOnOs +import org.junit.jupiter.api.condition.OS +import java.nio.file.Files +import java.nio.file.Path +import kotlin.io.path.pathString + +object WSLUtil { + fun wslPath(path: Path): String { + if (SystemUtils.IS_OS_WINDOWS) { + val absolutePath = path.toAbsolutePath() + val t = (0..