Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow build with TestContainers' test for kotlin-dsl on docker in WSL2 without desktop #37

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions kotlin-dsl/dsl/src/test/kotlin/blackbox/IntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ 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

@Testcontainers
class IntegrationTest {

companion object {
var chutneyServer: GenericContainer<Nothing>? = null
private var chutneyServer: GenericContainer<Nothing>? = 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
)
Expand All @@ -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
Expand Down
47 changes: 47 additions & 0 deletions kotlin-dsl/dsl/src/test/kotlin/util/WSLUtil.kt
Original file line number Diff line number Diff line change
@@ -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..<absolutePath.nameCount).map(absolutePath::getName).map(Path::toString).toTypedArray()
return listOf("mnt", absolutePath.root.toString().substring(0, 1), *t).joinToString("/", "/")
}
return path.pathString
}
}

class WSLUtilTest {
@Test
@EnabledOnOs(OS.WINDOWS)
fun wslPath() {
val dir = Files.createTempDirectory("wslPath-")
assertThat(WSLUtil.wslPath(dir)).startsWith("/mnt/")
}
}
Loading