Skip to content

Commit 3324220

Browse files
committed
add test for resolving env, correctly create attribute
1 parent ac21daf commit 3324220

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

runtime/auth/http-auth/common/src/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package aws.smithy.kotlin.runtime.http.auth
77
import aws.smithy.kotlin.runtime.businessmetrics.SmithyBusinessMetric
88
import aws.smithy.kotlin.runtime.businessmetrics.emitBusinessMetric
99
import aws.smithy.kotlin.runtime.collections.Attributes
10-
import aws.smithy.kotlin.runtime.collections.toMutableAttributes
10+
import aws.smithy.kotlin.runtime.collections.mutableAttributes
1111
import aws.smithy.kotlin.runtime.time.Instant
1212
import aws.smithy.kotlin.runtime.util.PlatformProvider
1313

@@ -23,7 +23,7 @@ public class EnvironmentBearerTokenProvider(
2323
?: error("$key environment variable is not set")
2424
return object : BearerToken {
2525
override val token: String = bearerToken
26-
override val attributes: Attributes = attributes.toMutableAttributes().apply {
26+
override val attributes: Attributes = mutableAttributes().apply {
2727
emitBusinessMetric(SmithyBusinessMetric.BEARER_SERVICE_ENV_VARS)
2828
}
2929
override val expiration: Instant? = null

runtime/auth/http-auth/common/test/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProviderTest.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ import kotlin.test.assertFailsWith
88

99
class EnvironmentBearerTokenProviderTest {
1010
@Test
11-
fun testResolveWithValidToken() = runTest {
11+
fun testResolveFromEnvVar() = runTest {
1212
val provider = EnvironmentBearerTokenProvider(
1313
"TEST_TOKEN",
1414
TestPlatformProvider(
1515
env = mutableMapOf("TEST_TOKEN" to "test-env-bearer-token"),
16+
),
17+
)
18+
19+
val token = provider.resolve()
20+
21+
assertEquals("test-env-bearer-token", token.token)
22+
}
23+
24+
@Test
25+
fun testResolveFromSysProps() = runTest {
26+
val provider = EnvironmentBearerTokenProvider(
27+
"TEST_TOKEN",
28+
TestPlatformProvider(
1629
props = mutableMapOf("TEST_TOKEN" to "test-sys-props-bearer-token"),
1730
),
1831
)

0 commit comments

Comments
 (0)