|
4 | 4 | */ |
5 | 5 | package aws.sdk.kotlin.services.polly |
6 | 6 |
|
| 7 | +import aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider |
| 8 | +import aws.sdk.kotlin.services.polly.endpoints.DefaultEndpointProvider |
| 9 | +import aws.sdk.kotlin.services.polly.endpoints.EndpointParameters |
7 | 10 | import aws.sdk.kotlin.services.polly.model.OutputFormat |
8 | 11 | import aws.sdk.kotlin.services.polly.model.SynthesizeSpeechRequest |
9 | 12 | import aws.sdk.kotlin.services.polly.model.VoiceId |
| 13 | +import aws.sdk.kotlin.services.polly.presigners.PollyPresignConfig |
10 | 14 | import aws.sdk.kotlin.services.polly.presigners.presign |
11 | 15 | import aws.sdk.kotlin.testing.withAllEngines |
| 16 | +import aws.smithy.kotlin.runtime.auth.awssigning.SigningContextualizedEndpoint |
12 | 17 | import aws.smithy.kotlin.runtime.http.SdkHttpClient |
13 | 18 | import aws.smithy.kotlin.runtime.http.response.complete |
14 | 19 | import kotlinx.coroutines.runBlocking |
@@ -43,4 +48,37 @@ class PollyPresignerTest { |
43 | 48 | assertEquals(200, call.response.status.value, "presigned polly request failed for engine: $engine") |
44 | 49 | } |
45 | 50 | } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun presignConfigBasedPresign() = runBlocking { |
| 54 | + val request = SynthesizeSpeechRequest { |
| 55 | + voiceId = VoiceId.Salli |
| 56 | + outputFormat = OutputFormat.Pcm |
| 57 | + text = "hello world" |
| 58 | + } |
| 59 | + |
| 60 | + val presignConfig = PollyPresignConfig { |
| 61 | + credentialsProvider = DefaultChainCredentialsProvider() |
| 62 | + endpointProvider = { |
| 63 | + val endpoint = DefaultEndpointProvider().resolveEndpoint( |
| 64 | + EndpointParameters.invoke { |
| 65 | + region = it.region |
| 66 | + }, |
| 67 | + ) |
| 68 | + SigningContextualizedEndpoint(endpoint, it) |
| 69 | + } |
| 70 | + region = "us-east-1" |
| 71 | + } |
| 72 | + |
| 73 | + val presignedRequest = request.presign(presignConfig, 10.seconds) |
| 74 | + |
| 75 | + withAllEngines { engine -> |
| 76 | + val httpClient = SdkHttpClient(engine) |
| 77 | + |
| 78 | + val call = httpClient.call(presignedRequest) |
| 79 | + call.complete() |
| 80 | + |
| 81 | + assertEquals(200, call.response.status.value, "presigned polly request failed for engine: $engine") |
| 82 | + } |
| 83 | + } |
46 | 84 | } |
0 commit comments