-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...egen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RpcV2CborTest.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,103 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.smithy.kotlin.codegen.aws.protocols | ||
|
||
import software.amazon.smithy.kotlin.codegen.test.* | ||
import kotlin.test.Test | ||
|
||
class RpcV2CborTest { | ||
val model = """ | ||
${"$"}version: "2" | ||
namespace com.test | ||
use smithy.protocols#rpcv2Cbor | ||
use aws.api#service | ||
@rpcv2Cbor | ||
@service(sdkId: "CborExample") | ||
service CborExample { | ||
version: "1.0.0", | ||
operations: [GetFoo, GetFooStreaming] | ||
} | ||
@http(method: "POST", uri: "/foo") | ||
operation GetFoo {} | ||
@http(method: "POST", uri: "/foo-streaming") | ||
operation GetFooStreaming { | ||
input := {} | ||
output := { | ||
events: FooEvents | ||
} | ||
} | ||
// Model taken from https://smithy.io/2.0/spec/streaming.html#event-streams | ||
@streaming | ||
union FooEvents { | ||
up: Movement | ||
down: Movement | ||
left: Movement | ||
right: Movement | ||
throttlingError: ThrottlingError | ||
} | ||
structure Movement { | ||
velocity: Float | ||
} | ||
@error("client") | ||
@retryable(throttling: true) | ||
structure ThrottlingError {} | ||
""".toSmithyModel() | ||
|
||
@Test | ||
fun testStandardAcceptHeader() { | ||
val ctx = model.newTestContext("CborExample") | ||
|
||
val generator = RpcV2Cbor() | ||
generator.generateProtocolClient(ctx.generationCtx) | ||
|
||
ctx.generationCtx.delegator.finalize() | ||
ctx.generationCtx.delegator.flushWriters() | ||
|
||
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt") | ||
println(actual) | ||
val getFooMethod = actual.lines(" override suspend fun getFoo(input: GetFooRequest): GetFooResponse {", " }") | ||
|
||
val expectedHeaderMutation = """ | ||
op.install( | ||
MutateHeaders().apply { | ||
append("Accept", "application/cbor") | ||
} | ||
) | ||
""".replaceIndent(" ") | ||
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation) | ||
} | ||
|
||
@Test | ||
fun testEventStreamAcceptHeader() { | ||
val ctx = model.newTestContext("CborExample") | ||
|
||
val generator = RpcV2Cbor() | ||
generator.generateProtocolClient(ctx.generationCtx) | ||
|
||
ctx.generationCtx.delegator.finalize() | ||
ctx.generationCtx.delegator.flushWriters() | ||
|
||
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt") | ||
println(actual) | ||
val getFooMethod = actual.lines(" override suspend fun <T> getFooStreaming(input: GetFooStreamingRequest, block: suspend (GetFooStreamingResponse) -> T): T {", " }") | ||
|
||
val expectedHeaderMutation = """ | ||
op.install( | ||
MutateHeaders().apply { | ||
append("Accept", "application/vnd.amazon.eventstream") | ||
} | ||
) | ||
""".replaceIndent(" ") | ||
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation) | ||
} | ||
} |
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