Skip to content

Commit

Permalink
chore(): Allow build with TestContainers' test for kotlin-dsl on dock…
Browse files Browse the repository at this point in the history
…er in WSL2 without desktop (#37)
  • Loading branch information
boddissattva authored Mar 19, 2024
1 parent db522dd commit dc06444
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
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/")
}
}

0 comments on commit dc06444

Please sign in to comment.