Skip to content

Commit 430f1f8

Browse files
kggilmeraajtodd
andauthored
chore: coroutine version bump to 1.6.0 and Duration stabilization (#514)
* refactor tests to use `runTest` from `kotlinx-coroutines-test` * Duration API stabilization Co-authored-by: Aaron J Todd <todaaron@amazon.com>
1 parent eb23944 commit 430f1f8

File tree

64 files changed

+410
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+410
-276
lines changed

aws-runtime/aws-config/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
description = "Support for AWS configuration"
77
extra["moduleName"] = "aws.sdk.kotlin.runtime.config"
88

9-
val smithyKotlinVersion: String by project
9+
val coroutinesVersion: String by project
1010
val crtKotlinVersion: String by project
11-
1211
val kotestVersion: String by project
12+
val smithyKotlinVersion: String by project
1313

1414
kotlin {
1515
sourceSets {
1616
commonMain {
1717
dependencies {
1818
api(project(":aws-runtime:aws-core"))
1919
api(project(":aws-runtime:aws-types"))
20+
2021
implementation("aws.smithy.kotlin:logging:$smithyKotlinVersion")
2122
implementation("aws.smithy.kotlin:http:$smithyKotlinVersion")
2223
implementation("aws.smithy.kotlin:utils:$smithyKotlinVersion")
@@ -26,16 +27,15 @@ kotlin {
2627
// parsing common JSON credentials responses
2728
implementation("aws.smithy.kotlin:serde-json:$smithyKotlinVersion")
2829

29-
3030
// credential providers
3131
implementation("aws.sdk.kotlin.crt:aws-crt-kotlin:$crtKotlinVersion")
3232
implementation(project(":aws-runtime:crt-util"))
33-
3433
}
3534
}
3635
commonTest {
3736
dependencies {
3837
implementation(project(":aws-runtime:testing"))
38+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
3939
implementation("aws.smithy.kotlin:http-test:$smithyKotlinVersion")
4040
val kotlinxSerializationVersion: String by project
4141
val mockkVersion: String by project

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/CachedCredentialsProvider.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package aws.sdk.kotlin.runtime.auth.credentials
77

88
import aws.sdk.kotlin.crt.auth.credentials.build
99
import kotlin.time.Duration
10-
import kotlin.time.ExperimentalTime
1110
import aws.sdk.kotlin.crt.auth.credentials.CachedCredentialsProvider as CachedCredentialsProviderCrt
1211

1312
/**
@@ -24,7 +23,6 @@ import aws.sdk.kotlin.crt.auth.credentials.CachedCredentialsProvider as CachedCr
2423
*/
2524
public class CachedCredentialsProvider private constructor(builder: Builder) : CrtCredentialsProvider {
2625

27-
@OptIn(ExperimentalTime::class)
2826
override val crtProvider: CachedCredentialsProviderCrt = CachedCredentialsProviderCrt.build {
2927
refreshTimeInMilliseconds = builder.refreshTime.inWholeMilliseconds
3028

@@ -39,7 +37,6 @@ public class CachedCredentialsProvider private constructor(builder: Builder) : C
3937
public fun build(block: Builder.() -> Unit): CachedCredentialsProvider = Builder().apply(block).build()
4038
}
4139

42-
@OptIn(ExperimentalTime::class)
4340
public class Builder {
4441
/**
4542
* The provider to cache credentials query results from

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/JsonCredentialsDeserializer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal sealed class JsonCredentialsResponse {
4646
// // fields controlling the STS role:
4747
// "RoleArn": "...", // required
4848
// "RoleSessionName": "...", // required
49-
// // and also: DurationSeconds, ExternalId, SerialNumber, TokenCode, Policy
49+
// // and also: Duration, ExternalId, SerialNumber, TokenCode, Policy
5050
// ...
5151
// }
5252

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/StsAssumeRoleCredentialsProvider.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
77

88
import aws.sdk.kotlin.crt.auth.credentials.build
99
import aws.sdk.kotlin.runtime.crt.SdkDefaultIO
10+
import kotlin.time.Duration
1011
import aws.sdk.kotlin.crt.auth.credentials.StsAssumeRoleCredentialsProvider as StsAssumeRoleCredentialsProviderCrt
1112

1213
/**
@@ -15,20 +16,20 @@ import aws.sdk.kotlin.crt.auth.credentials.StsAssumeRoleCredentialsProvider as S
1516
* @param credentialsProvider The underlying Credentials Provider to use for source credentials
1617
* @param roleArn The target role's ARN
1718
* @param sessionName The name to associate with the session
18-
* @param durationSeconds The number of seconds from authentication that the session is valid for
19+
* @param duration Amount of time from authentication that the session is valid for
1920
*/
2021
public class StsAssumeRoleCredentialsProvider public constructor(
2122
credentialsProvider: CredentialsProvider,
2223
roleArn: String,
2324
sessionName: String,
24-
durationSeconds: Int? = null,
25+
duration: Duration? = null,
2526
) : CrtCredentialsProvider {
2627
override val crtProvider: StsAssumeRoleCredentialsProviderCrt = StsAssumeRoleCredentialsProviderCrt.build {
2728
clientBootstrap = SdkDefaultIO.ClientBootstrap
2829
tlsContext = SdkDefaultIO.TlsContext
2930
this.credentialsProvider = asCrt(credentialsProvider)
3031
this.roleArn = roleArn
3132
this.sessionName = sessionName
32-
this.durationSeconds = durationSeconds
33+
this.durationSeconds = duration?.inWholeSeconds?.toInt()
3334
}
3435
}

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/CachedValue.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import aws.smithy.kotlin.runtime.time.Instant
1010
import kotlinx.coroutines.sync.Mutex
1111
import kotlinx.coroutines.sync.withLock
1212
import kotlin.time.Duration
13-
import kotlin.time.ExperimentalTime
1413

1514
/**
1615
* A value with an expiration
@@ -26,7 +25,6 @@ internal data class ExpiringValue<T> (val value: T, val expiresAt: Instant)
2625
* expire BEFORE the actual expiration.
2726
* @param clock The clock to use for system time
2827
*/
29-
@OptIn(ExperimentalTime::class)
3028
internal class CachedValue<T> (
3129
private var value: ExpiringValue<T>? = null,
3230
private val bufferTime: Duration = Duration.ZERO,

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/ImdsClient.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import aws.smithy.kotlin.runtime.util.Platform
3232
import aws.smithy.kotlin.runtime.util.PlatformProvider
3333
import kotlin.time.Duration
3434
import kotlin.time.Duration.Companion.seconds
35-
import kotlin.time.ExperimentalTime
3635

3736
/**
3837
* Maximum time allowed by default (6 hours)
@@ -61,7 +60,6 @@ public interface InstanceMetadataProvider : Closeable {
6160
* See [transitioning to IMDSv2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2)
6261
* for more information.
6362
*/
64-
@OptIn(ExperimentalTime::class)
6563
public class ImdsClient private constructor(builder: Builder) : InstanceMetadataProvider {
6664
public constructor() : this(Builder())
6765

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import aws.smithy.kotlin.runtime.http.response.complete
1818
import aws.smithy.kotlin.runtime.time.Clock
1919
import kotlin.time.Duration
2020
import kotlin.time.Duration.Companion.seconds
21-
import kotlin.time.ExperimentalTime
2221

2322
/**
2423
* Tokens are cached to remove the need to reload the token between subsequent requests. To ensure
@@ -30,7 +29,6 @@ internal const val TOKEN_REFRESH_BUFFER_SECONDS = 120
3029
internal const val X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS = "x-aws-ec2-metadata-token-ttl-seconds"
3130
internal const val X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token"
3231

33-
@OptIn(ExperimentalTime::class)
3432
internal class TokenMiddleware(
3533
private val httpClient: SdkHttpClient,
3634
private val ttl: Duration = DEFAULT_TOKEN_TTL_SECONDS.seconds,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
package aws.sdk.kotlin.runtime.auth.credentials
77

88
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
9-
import aws.sdk.kotlin.runtime.testing.runSuspendTest
109
import io.kotest.matchers.string.shouldContain
10+
import kotlinx.coroutines.ExperimentalCoroutinesApi
11+
import kotlinx.coroutines.test.runTest
1112
import kotlin.test.Test
1213
import kotlin.test.assertEquals
1314
import kotlin.test.assertFailsWith
1415

16+
@OptIn(ExperimentalCoroutinesApi::class)
1517
class EnvironmentCredentialsProviderTest {
1618
private fun provider(vararg vars: Pair<String, String>) = EnvironmentCredentialsProvider((vars.toMap())::get)
1719

1820
@Test
19-
fun `it should read from environment variables (incl session token)`() = runSuspendTest {
21+
fun `it should read from environment variables (incl session token)`() = runTest {
2022
val provider = provider(
2123
AwsSdkSetting.AwsAccessKeyId.environmentVariable to "abc",
2224
AwsSdkSetting.AwsSecretAccessKey.environmentVariable to "def",
@@ -26,7 +28,7 @@ class EnvironmentCredentialsProviderTest {
2628
}
2729

2830
@Test
29-
fun `it should read from environment variables (excl session token)`() = runSuspendTest {
31+
fun `it should read from environment variables (excl session token)`() = runTest {
3032
val provider = provider(
3133
AwsSdkSetting.AwsAccessKeyId.environmentVariable to "abc",
3234
AwsSdkSetting.AwsSecretAccessKey.environmentVariable to "def",
@@ -35,14 +37,14 @@ class EnvironmentCredentialsProviderTest {
3537
}
3638

3739
@Test
38-
fun `it should throw an exception on missing access key`(): Unit = runSuspendTest {
40+
fun `it should throw an exception on missing access key`() = runTest {
3941
assertFailsWith<ProviderConfigurationException> {
4042
provider(AwsSdkSetting.AwsSecretAccessKey.environmentVariable to "def").getCredentials()
4143
}.message.shouldContain("Missing value for environment variable `AWS_ACCESS_KEY_ID`")
4244
}
4345

4446
@Test
45-
fun `it should throw an exception on missing secret key`(): Unit = runSuspendTest {
47+
fun `it should throw an exception on missing secret key`() = runTest {
4648
assertFailsWith<ProviderConfigurationException> {
4749
provider(AwsSdkSetting.AwsAccessKeyId.environmentVariable to "abc").getCredentials()
4850
}.message.shouldContain("Missing value for environment variable `AWS_SECRET_ACCESS_KEY`")

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package aws.sdk.kotlin.runtime.auth.credentials
88
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
99
import aws.sdk.kotlin.runtime.config.imds.*
1010
import aws.sdk.kotlin.runtime.testing.TestPlatformProvider
11-
import aws.sdk.kotlin.runtime.testing.runSuspendTest
1211
import aws.smithy.kotlin.runtime.http.Headers
1312
import aws.smithy.kotlin.runtime.http.HttpBody
1413
import aws.smithy.kotlin.runtime.http.HttpStatusCode
@@ -18,15 +17,18 @@ import aws.smithy.kotlin.runtime.httptest.buildTestConnection
1817
import aws.smithy.kotlin.runtime.time.Instant
1918
import aws.smithy.kotlin.runtime.time.ManualClock
2019
import io.kotest.matchers.string.shouldContain
20+
import kotlinx.coroutines.ExperimentalCoroutinesApi
21+
import kotlinx.coroutines.test.runTest
2122
import kotlin.test.Test
2223
import kotlin.test.assertEquals
2324
import kotlin.test.assertFailsWith
2425
import kotlin.test.assertIs
2526

27+
@OptIn(ExperimentalCoroutinesApi::class)
2628
class ImdsCredentialsProviderTest {
2729

2830
@Test
29-
fun testImdsDisabled(): Unit = runSuspendTest {
31+
fun testImdsDisabled() = runTest {
3032
val platform = TestPlatformProvider(
3133
env = mapOf(AwsSdkSetting.AwsEc2MetadataDisabled.environmentVariable to "true")
3234
)
@@ -37,7 +39,7 @@ class ImdsCredentialsProviderTest {
3739
}
3840

3941
@Test
40-
fun testSuccess(): Unit = runSuspendTest {
42+
fun testSuccess() = runTest {
4143
val connection = buildTestConnection {
4244
expect(
4345
tokenRequest("http://169.254.169.254", DEFAULT_TOKEN_TTL_SECONDS),
@@ -84,7 +86,7 @@ class ImdsCredentialsProviderTest {
8486
}
8587

8688
@Test
87-
fun testSuccessProfileOverride(): Unit = runSuspendTest {
89+
fun testSuccessProfileOverride() = runTest {
8890
val connection = buildTestConnection {
8991
expect(
9092
tokenRequest("http://169.254.169.254", DEFAULT_TOKEN_TTL_SECONDS),
@@ -128,7 +130,7 @@ class ImdsCredentialsProviderTest {
128130
}
129131

130132
@Test
131-
fun testTokenFailure(): Unit = runSuspendTest {
133+
fun testTokenFailure() = runTest {
132134
// when attempting to retrieve initial token, IMDS replied with 403, indicating IMDS is disabled or not allowed through permissions
133135
val connection = buildTestConnection {
134136
expect(
@@ -154,7 +156,7 @@ class ImdsCredentialsProviderTest {
154156
}
155157

156158
@Test
157-
fun testNoInstanceProfileConfigured(): Unit = runSuspendTest {
159+
fun testNoInstanceProfileConfigured() = runTest {
158160

159161
val connection = buildTestConnection {
160162
expect(

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55

66
package aws.sdk.kotlin.runtime.auth.credentials
77

8-
import aws.sdk.kotlin.runtime.testing.runSuspendTest
98
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
109
import aws.smithy.kotlin.runtime.time.Instant
1110
import io.kotest.matchers.string.shouldContain
11+
import kotlinx.coroutines.ExperimentalCoroutinesApi
12+
import kotlinx.coroutines.test.runTest
1213
import kotlin.test.Test
1314
import kotlin.test.assertEquals
1415
import kotlin.test.assertFailsWith
1516

17+
@OptIn(ExperimentalCoroutinesApi::class)
1618
class JsonCredentialsDeserializerTest {
1719
@Test
18-
fun testSuccessResponse() = runSuspendTest {
20+
fun testSuccessResponse() = runTest {
1921
val payload = """
2022
{
2123
"Code" : "Success",
@@ -40,7 +42,7 @@ class JsonCredentialsDeserializerTest {
4042
}
4143

4244
@Test
43-
fun testInvalidJson(): Unit = runSuspendTest {
45+
fun testInvalidJson() = runTest {
4446
val payload = "404: not found"
4547
val deserializer = JsonDeserializer(payload.encodeToByteArray())
4648

@@ -51,7 +53,7 @@ class JsonCredentialsDeserializerTest {
5153
}
5254

5355
@Test
54-
fun testSuccessResponseMissingCode() = runSuspendTest {
56+
fun testSuccessResponseMissingCode() = runTest {
5557
val payload = """
5658
{
5759
"LastUpdated" : "2021-09-17T20:57:08Z",
@@ -75,7 +77,7 @@ class JsonCredentialsDeserializerTest {
7577
}
7678

7779
@Test
78-
fun testMissingAccessKeyId() = runSuspendTest {
80+
fun testMissingAccessKeyId() = runTest {
7981
val payload = """
8082
{
8183
"LastUpdated" : "2021-09-17T20:57:08Z",
@@ -93,7 +95,7 @@ class JsonCredentialsDeserializerTest {
9395
}
9496

9597
@Test
96-
fun testMissingSecretAccessKey() = runSuspendTest {
98+
fun testMissingSecretAccessKey() = runTest {
9799
val payload = """
98100
{
99101
"LastUpdated" : "2021-09-17T20:57:08Z",
@@ -111,7 +113,7 @@ class JsonCredentialsDeserializerTest {
111113
}
112114

113115
@Test
114-
fun testMissingSessionToken() = runSuspendTest {
116+
fun testMissingSessionToken() = runTest {
115117
val payload = """
116118
{
117119
"LastUpdated" : "2021-09-17T20:57:08Z",
@@ -129,7 +131,7 @@ class JsonCredentialsDeserializerTest {
129131
}
130132

131133
@Test
132-
fun testErrorResponse() = runSuspendTest {
134+
fun testErrorResponse() = runTest {
133135
val payload = """
134136
{
135137
"Code" : "AssumeRoleUnauthorizedAccess",

0 commit comments

Comments
 (0)