-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor environment variables for integration tests
- Loading branch information
1 parent
60761bc
commit 1f54639
Showing
7 changed files
with
11 additions
and
61 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
integ-tests/src/commonTest/kotlin/dev/evo/elasticmagic/engine.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 |
---|---|---|
@@ -1,14 +1,5 @@ | ||
package dev.evo.elasticmagic | ||
|
||
import dev.evo.elasticmagic.transport.Auth | ||
|
||
import io.ktor.client.engine.HttpClientEngine | ||
|
||
const val DEFAULT_ELASTIC_URL = "http://localhost:9200" | ||
const val DEFAULT_ELASTIC_USER = "elastic" | ||
|
||
expect val elasticUrl: String | ||
|
||
expect val httpEngine: HttpClientEngine | ||
|
||
expect val elasticAuth: Auth? |
24 changes: 0 additions & 24 deletions
24
integ-tests/src/jsTest/kotlin/dev/evo/elasticmagic/engineJs.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 |
---|---|---|
@@ -1,30 +1,6 @@ | ||
package dev.evo.elasticmagic | ||
|
||
import dev.evo.elasticmagic.transport.Auth | ||
|
||
import io.ktor.client.engine.HttpClientEngine | ||
import io.ktor.client.engine.js.Js | ||
|
||
external val process: Process | ||
|
||
external interface Process { | ||
val env: ProcessEnvVariables | ||
} | ||
|
||
external object ProcessEnvVariables { | ||
val ELASTIC_URL: String? | ||
val ELASTIC_USER: String? | ||
val ELASTIC_PASSWORD: String? | ||
} | ||
|
||
actual val elasticUrl: String = process.env.ELASTIC_URL ?: DEFAULT_ELASTIC_URL | ||
|
||
actual val httpEngine: HttpClientEngine = Js.create {} | ||
|
||
actual val elasticAuth: Auth? = when (val elasticPassword = process.env.ELASTIC_PASSWORD) { | ||
null -> null | ||
else -> Auth.Basic( | ||
process.env.ELASTIC_USER ?: DEFAULT_ELASTIC_USER, | ||
elasticPassword | ||
) | ||
} |
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,3 @@ | ||
package dev.evo.elasticmagic | ||
|
||
actual fun getenv(name: String): String? = js("process.env[name]") as String? |
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
3 changes: 3 additions & 0 deletions
3
integ-tests/src/jvmTest/kotlin/dev/evo/elasticmagic/envJvm.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,3 @@ | ||
package dev.evo.elasticmagic | ||
|
||
actual fun getenv(name: String): String? = System.getenv(name) |
16 changes: 0 additions & 16 deletions
16
integ-tests/src/nativeTest/kotlin/dev/evo/elasticmagic/engineNative.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 |
---|---|---|
@@ -1,24 +1,8 @@ | ||
package dev.evo.elasticmagic | ||
|
||
import dev.evo.elasticmagic.transport.Auth | ||
|
||
import io.ktor.client.engine.HttpClientEngine | ||
import io.ktor.client.engine.curl.Curl | ||
|
||
import kotlinx.cinterop.toKString | ||
|
||
import platform.posix.getenv | ||
|
||
actual val elasticUrl: String = getenv("ELASTIC_URL")?.toKString() ?: DEFAULT_ELASTIC_URL | ||
|
||
actual val httpEngine: HttpClientEngine = Curl.create { | ||
sslVerify = false | ||
} | ||
|
||
actual val elasticAuth: Auth? = when (val elasticPassword = getenv("ELASTIC_PASSWORD")?.toKString()) { | ||
null -> null | ||
else -> Auth.Basic( | ||
getenv("ELASTIC_USER")?.toKString() ?: DEFAULT_ELASTIC_USER, | ||
elasticPassword | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
integ-tests/src/nativeTest/kotlin/dev/evo/elasticmagic/envNative.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,5 @@ | ||
package dev.evo.elasticmagic | ||
|
||
import kotlinx.cinterop.toKString | ||
|
||
actual fun getenv(name: String): String? = platform.posix.getenv(name)?.toKString() |