-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix KMS tests by fixing
Send
bound on fluent send method (#2695)
## Motivation and Context This PR fixes the KMS tests when the generating code in orchestrator mode by ensuring the `Future` returned by `send()` implements `Send`, and also adds a codegen unit test for this so that it's checked at the generic client level. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
- Loading branch information
1 parent
3dad4e3
commit 9bf3f04
Showing
11 changed files
with
155 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
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
79 changes: 79 additions & 0 deletions
79
...e/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGeneratorTest.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,79 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.smithy.generators.client | ||
|
||
import org.junit.jupiter.api.Test | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.testutil.TestCodegenSettings | ||
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest | ||
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency | ||
import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate | ||
import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType | ||
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate | ||
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel | ||
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest | ||
|
||
class FluentClientGeneratorTest { | ||
val model = """ | ||
namespace com.example | ||
use aws.protocols#awsJson1_0 | ||
@awsJson1_0 | ||
service HelloService { | ||
operations: [SayHello], | ||
version: "1" | ||
} | ||
operation SayHello { input: TestInput } | ||
structure TestInput {} | ||
""".asSmithyModel() | ||
|
||
@Test | ||
fun `send() future implements Send`() { | ||
val test: (ClientCodegenContext, RustCrate) -> Unit = { codegenContext, rustCrate -> | ||
rustCrate.integrationTest("send_future_is_send") { | ||
val moduleName = codegenContext.moduleUseName() | ||
rustTemplate( | ||
""" | ||
fn check_send<T: Send>(_: T) {} | ||
##[test] | ||
fn test() { | ||
let connector = #{TestConnection}::<#{SdkBody}>::new(Vec::new()); | ||
let config = $moduleName::Config::builder() | ||
.endpoint_resolver("http://localhost:1234") | ||
#{set_http_connector} | ||
.build(); | ||
let smithy_client = aws_smithy_client::Builder::new() | ||
.connector(connector.clone()) | ||
.middleware_fn(|r| r) | ||
.build_dyn(); | ||
let client = $moduleName::Client::with_config(smithy_client, config); | ||
check_send(client.say_hello().send()); | ||
} | ||
""", | ||
"TestConnection" to CargoDependency.smithyClient(codegenContext.runtimeConfig) | ||
.withFeature("test-util").toType() | ||
.resolve("test_connection::TestConnection"), | ||
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), | ||
"set_http_connector" to writable { | ||
if (codegenContext.smithyRuntimeMode.generateOrchestrator) { | ||
rust(".http_connector(connector.clone())") | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
clientIntegrationTest(model, TestCodegenSettings.middlewareModeTestParams, test = test) | ||
clientIntegrationTest( | ||
model, | ||
TestCodegenSettings.orchestratorModeTestParams, | ||
test = test, | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rc/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestCodegenSettings.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,38 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.testutil | ||
|
||
import software.amazon.smithy.model.node.ObjectNode | ||
import software.amazon.smithy.model.node.StringNode | ||
import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams | ||
|
||
object TestCodegenSettings { | ||
// TODO(enableNewSmithyRuntime): Delete this when removing `enableNewSmithyRuntime` feature gate | ||
fun middlewareMode(): ObjectNode = ObjectNode.objectNodeBuilder() | ||
.withMember( | ||
"codegen", | ||
ObjectNode.objectNodeBuilder() | ||
.withMember("enableNewSmithyRuntime", StringNode.from("middleware")).build(), | ||
) | ||
.build() | ||
|
||
// TODO(enableNewSmithyRuntime): Delete this when removing `enableNewSmithyRuntime` feature gate | ||
fun orchestratorMode(): ObjectNode = ObjectNode.objectNodeBuilder() | ||
.withMember( | ||
"codegen", | ||
ObjectNode.objectNodeBuilder() | ||
.withMember("enableNewSmithyRuntime", StringNode.from("orchestrator")).build(), | ||
) | ||
.build() | ||
|
||
// TODO(enableNewSmithyRuntime): Delete this when removing `enableNewSmithyRuntime` feature gate | ||
val middlewareModeTestParams get(): IntegrationTestParams = | ||
IntegrationTestParams(additionalSettings = middlewareMode()) | ||
|
||
// TODO(enableNewSmithyRuntime): Delete this when removing `enableNewSmithyRuntime` feature gate | ||
val orchestratorModeTestParams get(): IntegrationTestParams = | ||
IntegrationTestParams(additionalSettings = orchestratorMode()) | ||
} |
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
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
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
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
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