Skip to content

Commit 3fce507

Browse files
authored
misc: enable disabled kotlin native tests (#1593)
1 parent 4f7da01 commit 3fce507

File tree

5 files changed

+142
-102
lines changed

5 files changed

+142
-102
lines changed

aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/auth/credentials/EcsCredentialsProviderTest.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
99
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
1010
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
1111
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
12-
import aws.smithy.kotlin.runtime.IgnoreNative
1312
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
1413
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
1514
import aws.smithy.kotlin.runtime.http.Headers
@@ -144,9 +143,6 @@ class EcsCredentialsProviderTest {
144143
engine.assertRequests()
145144
}
146145

147-
// FIXME iosSimulator fails with a different exception: "Failed to resolve host amazonaws.com: nodename nor servname provided, or not known"
148-
// Need to fix this by applying the same --standalone removal that we do in smithy-kotlin, aws-crt-kotlin. See `configureIosSimulatorTasks` in aws-kotlin-repo-tools.
149-
@IgnoreNative
150146
@Test
151147
fun testNonLocalFullUri() = runTest {
152148
val uri = "http://amazonaws.com/full"

aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainTest.kt

Lines changed: 85 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,15 @@
66
package aws.sdk.kotlin.runtime.region
77

88
import aws.sdk.kotlin.runtime.util.TestInstanceMetadataProvider
9-
import aws.smithy.kotlin.runtime.IgnoreNative
109
import aws.smithy.kotlin.runtime.util.TestPlatformProvider
11-
import kotlinx.coroutines.test.runTest
10+
import kotlinx.coroutines.runBlocking
1211
import kotlinx.serialization.json.*
1312
import kotlin.test.Test
1413
import kotlin.test.assertEquals
1514

1615
class DefaultRegionProviderChainTest {
17-
private data class RegionProviderChainTest(
18-
val name: String,
19-
val platformProvider: TestPlatformProvider,
20-
val instanceMetadataProvider: TestInstanceMetadataProvider,
21-
val region: String?,
22-
val targets: List<String> = emptyList(),
23-
)
24-
25-
// FIXME "jvm property is favored" tests need to be made JVM-only. Native does not have system properties, so those tests will always fail.
26-
@IgnoreNative
2716
@Test
28-
fun testSuite() = runTest {
29-
val tests = Json.parseToJsonElement(REGION_PROVIDER_CHAIN_TEST_SUITE).jsonArray
30-
.map { it.jsonObject }
31-
.map {
32-
val name = it["name"]!!.jsonPrimitive.content
33-
val platform = TestPlatformProvider.fromJsonNode(it["platform"]!!.jsonObject)
34-
val instanceMetadata = TestInstanceMetadataProvider.fromJsonNode(it["imds"]!!.jsonObject)
35-
val region = it["region"]!!.jsonPrimitive.contentOrNull
36-
RegionProviderChainTest(name, platform, instanceMetadata, region)
37-
}
38-
39-
tests.forEach { test ->
40-
val provider = DefaultRegionProviderChain(
41-
platformProvider = test.platformProvider,
42-
imdsClient = lazy { test.instanceMetadataProvider },
43-
)
44-
val actual = provider.getRegion()
45-
assertEquals(test.region, actual, test.name)
46-
}
47-
}
48-
}
49-
50-
/**
51-
* Construct a [TestPlatformProvider] from a JSON node like:
52-
*
53-
* ```json
54-
* {
55-
* "env": {
56-
* "ENV_VAR": "value"
57-
* },
58-
* "props": {
59-
* "aws.property": "value"
60-
* },
61-
* "fs": {
62-
* "filename": "contents"
63-
* }
64-
* }
65-
* ```
66-
*/
67-
fun TestPlatformProvider.Companion.fromJsonNode(obj: JsonObject): TestPlatformProvider {
68-
val env = obj["env"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
69-
val props = obj["props"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
70-
val fs = obj["fs"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
71-
return TestPlatformProvider(env, props, fs)
72-
}
73-
74-
/**
75-
* Construct a [TestInstanceMetadataProvider] from a JSON object containing metadata as key-value pairs.
76-
*/
77-
fun TestInstanceMetadataProvider.Companion.fromJsonNode(obj: JsonObject): TestInstanceMetadataProvider {
78-
val metadata = obj.jsonObject.mapValues { it.value.jsonPrimitive.content }
79-
return TestInstanceMetadataProvider(metadata)
17+
fun testSuite() = runRegionProviderChainTestSuite(REGION_PROVIDER_CHAIN_TEST_SUITE)
8018
}
8119

8220
// language=JSON
@@ -104,20 +42,6 @@ private const val REGION_PROVIDER_CHAIN_TEST_SUITE = """
10442
"imds": {},
10543
"region": "us-east-2"
10644
},
107-
{
108-
"name": "jvm property is favored",
109-
"platform": {
110-
"env": {
111-
"AWS_REGION": "us-east-2"
112-
},
113-
"props": {
114-
"aws.region": "us-west-1"
115-
},
116-
"fs": {}
117-
},
118-
"imds": {},
119-
"region": "us-west-1"
120-
},
12145
{
12246
"name": "default profile",
12347
"platform": {
@@ -160,31 +84,17 @@ private const val REGION_PROVIDER_CHAIN_TEST_SUITE = """
16084
"region": "us-east-1"
16185
},
16286
{
163-
"name": "jvm system properties are favored over imds",
87+
"name": "environment variables are favored over imds",
16488
"platform": {
16589
"env": {
166-
"AWS_REGION": "us-east-2"
90+
"AWS_REGION": "us-west-1"
16791
},
16892
"props": {},
16993
"fs": {}
17094
},
17195
"imds": {
17296
"/latest/meta-data/placement/region": "us-east-1"
17397
},
174-
"region": "us-east-2"
175-
},
176-
{
177-
"name": "environment variables are favored over imds",
178-
"platform": {
179-
"env": {},
180-
"props": {
181-
"aws.region": "us-west-1"
182-
},
183-
"fs": {}
184-
},
185-
"imds": {
186-
"/latest/meta-data/placement/region": "us-east-1"
187-
},
18898
"region": "us-west-1"
18999
},
190100
{
@@ -205,3 +115,84 @@ private const val REGION_PROVIDER_CHAIN_TEST_SUITE = """
205115
}
206116
]
207117
"""
118+
119+
private data class RegionProviderChainTest(
120+
val name: String,
121+
val platformProvider: TestPlatformProvider,
122+
val instanceMetadataProvider: TestInstanceMetadataProvider,
123+
val region: String?,
124+
val targets: List<String> = emptyList(),
125+
)
126+
127+
/**
128+
* Construct a [TestPlatformProvider] from a JSON node like:
129+
*
130+
* ```json
131+
* {
132+
* "env": {
133+
* "ENV_VAR": "value"
134+
* },
135+
* "props": {
136+
* "aws.property": "value"
137+
* },
138+
* "fs": {
139+
* "filename": "contents"
140+
* }
141+
* }
142+
* ```
143+
*/
144+
/**
145+
* Construct a [TestPlatformProvider] from a JSON node like:
146+
*
147+
* ```json
148+
* {
149+
* "env": {
150+
* "ENV_VAR": "value"
151+
* },
152+
* "props": {
153+
* "aws.property": "value"
154+
* },
155+
* "fs": {
156+
* "filename": "contents"
157+
* }
158+
* }
159+
* ```
160+
*/
161+
private fun TestPlatformProvider.Companion.fromJsonNode(obj: JsonObject): TestPlatformProvider {
162+
val env = obj["env"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
163+
val props = obj["props"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
164+
val fs = obj["fs"]?.jsonObject?.mapValues { it.value.jsonPrimitive.content } ?: emptyMap()
165+
return TestPlatformProvider(env, props, fs)
166+
}
167+
168+
/**
169+
* Construct a [TestInstanceMetadataProvider] from a JSON object containing metadata as key-value pairs.
170+
*/
171+
/**
172+
* Construct a [TestInstanceMetadataProvider] from a JSON object containing metadata as key-value pairs.
173+
*/
174+
private fun TestInstanceMetadataProvider.Companion.fromJsonNode(obj: JsonObject): TestInstanceMetadataProvider {
175+
val metadata = obj.jsonObject.mapValues { it.value.jsonPrimitive.content }
176+
return TestInstanceMetadataProvider(metadata)
177+
}
178+
179+
internal fun runRegionProviderChainTestSuite(testSuite: String) = runBlocking {
180+
val tests = Json.parseToJsonElement(testSuite).jsonArray
181+
.map { it.jsonObject }
182+
.map {
183+
val name = it["name"]!!.jsonPrimitive.content
184+
val platform = TestPlatformProvider.fromJsonNode(it["platform"]!!.jsonObject)
185+
val instanceMetadata = TestInstanceMetadataProvider.fromJsonNode(it["imds"]!!.jsonObject)
186+
val region = it["region"]!!.jsonPrimitive.contentOrNull
187+
RegionProviderChainTest(name, platform, instanceMetadata, region)
188+
}
189+
190+
tests.forEach { test ->
191+
val provider = DefaultRegionProviderChain(
192+
platformProvider = test.platformProvider,
193+
imdsClient = lazy { test.instanceMetadataProvider },
194+
)
195+
val actual = provider.getRegion()
196+
assertEquals(test.region, actual, test.name)
197+
}
198+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package aws.sdk.kotlin.runtime.region
7+
8+
import kotlin.test.Test
9+
10+
class DefaultRegionProviderChainTestJVM {
11+
@Test
12+
fun testSuite() = runRegionProviderChainTestSuite(JVM_REGION_PROVIDER_CHAIN_TEST_SUITE)
13+
}
14+
15+
// language=JSON
16+
private const val JVM_REGION_PROVIDER_CHAIN_TEST_SUITE = """
17+
[
18+
{
19+
"name": "jvm property is favored",
20+
"platform": {
21+
"env": {
22+
"AWS_REGION": "us-east-2"
23+
},
24+
"props": {
25+
"aws.region": "us-west-1"
26+
},
27+
"fs": {}
28+
},
29+
"imds": {},
30+
"region": "us-west-1"
31+
},
32+
{
33+
"name": "jvm system properties are favored over imds",
34+
"platform": {
35+
"env": {},
36+
"props": {
37+
"aws.region": "us-east-2"
38+
},
39+
"fs": {}
40+
},
41+
"imds": {
42+
"/latest/meta-data/placement/region": "us-east-1"
43+
},
44+
"region": "us-east-2"
45+
}
46+
]
47+
"""

aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/auth/credentials/executeCommandNative.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ internal actual suspend fun executeCommand(
4848
}
4949

5050
val shell = when (platformProvider.osInfo().family) {
51-
OsFamily.Windows -> "cmd.exe"
52-
else -> "sh"
51+
OsFamily.Windows -> "C:\\Windows\\System32\\cmd.exe"
52+
else -> "/bin/sh"
5353
}
5454

5555
val shellArg = when (platformProvider.osInfo().family) {
5656
OsFamily.Windows -> "/C"
5757
else -> "-c"
5858
}
5959

60-
val argv = memScoped { (arrayOf(shell, shellArg, command).map { it.cstr.ptr } + null).toCValues() }
61-
execvp(shell, argv)
60+
memScoped {
61+
val argv = (arrayOf(shell, shellArg, command).map { it.cstr.ptr } + null).toCValues()
62+
execvp(shell, argv)
63+
}
6264
_exit(127) // If exec fails
6365
}
6466

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
import aws.sdk.kotlin.gradle.dsl.configureLinting
66
import aws.sdk.kotlin.gradle.dsl.configureNexus
7+
import aws.sdk.kotlin.gradle.kmp.configureIosSimulatorTasks
78
import aws.sdk.kotlin.gradle.util.typedProp
89
import java.net.URL
910

@@ -23,6 +24,7 @@ plugins {
2324
alias(libs.plugins.kotlin.multiplatform) apply false
2425
alias(libs.plugins.kotlin.jvm) apply false
2526
alias(libs.plugins.aws.kotlin.repo.tools.artifactsizemetrics)
27+
alias(libs.plugins.aws.kotlin.repo.tools.kmp)
2628
}
2729

2830
artifactSizeMetrics {
@@ -116,6 +118,8 @@ allprojects {
116118

117119
// Enables running `./gradlew allDeps` to get a comprehensive list of dependencies for every subproject
118120
tasks.register<DependencyReportTask>("allDeps") { }
121+
122+
configureIosSimulatorTasks()
119123
}
120124

121125
project.afterEvaluate {

0 commit comments

Comments
 (0)