-
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.
Allow integration tests to run in both runtime modes (#2709)
## Description This will allow integration tests under `aws/sdk/integration-tests` to run in both smithy runtime modes. Prior to the PR, the integration tests use `map_operation` to customize operations, which is not supported in the orchestrator, preventing us from running them in the orchestrator mode. Fortunately, all the usages of `map_operation` in the integration tests involve setting a test request time and a test user agent in a property bag. This PR stops using `map_operation` in those tests and instead introduces separate test helper methods in both runtime modes: one for setting a test request and the other for setting a test user agent. They allow the integration tests to compile and run in both modes. Note that the integration tests in the orchestrator do not necessarily pass at this time. We'll address the failures subsequently. ## Testing Confirmed integration tests continue passing with the changes when run in the middleware . Confirmed those complied (but not necessarily passed) in the orchestrator. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Yuki Saito <[email protected]>
- Loading branch information
1 parent
3a9e64e
commit 61b7a77
Showing
18 changed files
with
252 additions
and
119 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...degen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCustomizableOperationDecorator.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.rustsdk | ||
|
||
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationSection | ||
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency | ||
import software.amazon.smithy.rust.codegen.core.rustlang.Writable | ||
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.RuntimeConfig | ||
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType | ||
|
||
class CustomizableOperationTestHelpers(runtimeConfig: RuntimeConfig) : | ||
CustomizableOperationCustomization() { | ||
private val codegenScope = arrayOf( | ||
*RuntimeType.preludeScope, | ||
"AwsUserAgent" to AwsRuntimeType.awsHttp(runtimeConfig) | ||
.resolve("user_agent::AwsUserAgent"), | ||
"BeforeTransmitInterceptorContextMut" to RuntimeType.smithyRuntimeApi(runtimeConfig) | ||
.resolve("client::interceptors::BeforeTransmitInterceptorContextMut"), | ||
"ConfigBag" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("config_bag::ConfigBag"), | ||
"ConfigBagAccessors" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::orchestrator::ConfigBagAccessors"), | ||
"http" to CargoDependency.Http.toType(), | ||
"InterceptorContext" to RuntimeType.smithyRuntimeApi(runtimeConfig) | ||
.resolve("client::interceptors::InterceptorContext"), | ||
"RequestTime" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::orchestrator::RequestTime"), | ||
"SharedInterceptor" to RuntimeType.smithyRuntimeApi(runtimeConfig) | ||
.resolve("client::interceptors::SharedInterceptor"), | ||
"TestParamsSetterInterceptor" to CargoDependency.smithyRuntime(runtimeConfig).withFeature("test-util") | ||
.toType().resolve("client::test_util::interceptor::TestParamsSetterInterceptor"), | ||
) | ||
|
||
override fun section(section: CustomizableOperationSection): Writable = | ||
writable { | ||
if (section is CustomizableOperationSection.CustomizableOperationImpl) { | ||
if (section.operationShape == null) { | ||
// TODO(enableNewSmithyRuntime): Delete this branch when middleware is no longer used | ||
// This branch customizes CustomizableOperation in the middleware. section.operationShape being | ||
// null means that this customization is rendered in a place where we don't need to figure out | ||
// the module for an operation (which is the case for CustomizableOperation in the middleware | ||
// that is rendered in the customize module). | ||
rustTemplate( | ||
""" | ||
##[doc(hidden)] | ||
// This is a temporary method for testing. NEVER use it in production | ||
pub fn request_time_for_tests(mut self, request_time: ::std::time::SystemTime) -> Self { | ||
self.operation.properties_mut().insert(request_time); | ||
self | ||
} | ||
##[doc(hidden)] | ||
// This is a temporary method for testing. NEVER use it in production | ||
pub fn user_agent_for_tests(mut self) -> Self { | ||
self.operation.properties_mut().insert(#{AwsUserAgent}::for_tests()); | ||
self | ||
} | ||
""", | ||
*codegenScope, | ||
) | ||
} else { | ||
// The else branch is for rendering customization for the orchestrator. | ||
rustTemplate( | ||
""" | ||
##[doc(hidden)] | ||
// This is a temporary method for testing. NEVER use it in production | ||
pub fn request_time_for_tests(mut self, request_time: ::std::time::SystemTime) -> Self { | ||
use #{ConfigBagAccessors}; | ||
let interceptor = #{TestParamsSetterInterceptor}::new(move |_: &mut #{BeforeTransmitInterceptorContextMut}<'_>, cfg: &mut #{ConfigBag}| { | ||
cfg.set_request_time(#{RequestTime}::new(request_time)); | ||
}); | ||
self.interceptors.push(#{SharedInterceptor}::new(interceptor)); | ||
self | ||
} | ||
##[doc(hidden)] | ||
// This is a temporary method for testing. NEVER use it in production | ||
pub fn user_agent_for_tests(mut self) -> Self { | ||
let interceptor = #{TestParamsSetterInterceptor}::new(|context: &mut #{BeforeTransmitInterceptorContextMut}<'_>, _: &mut #{ConfigBag}| { | ||
let headers = context.request_mut().headers_mut(); | ||
let user_agent = #{AwsUserAgent}::for_tests(); | ||
headers.insert( | ||
#{http}::header::USER_AGENT, | ||
#{http}::HeaderValue::try_from(user_agent.ua_header()).unwrap(), | ||
); | ||
headers.insert( | ||
#{http}::HeaderName::from_static("x-amz-user-agent"), | ||
#{http}::HeaderValue::try_from(user_agent.aws_ua_header()).unwrap(), | ||
); | ||
}); | ||
self.interceptors.push(#{SharedInterceptor}::new(interceptor)); | ||
self | ||
} | ||
""", | ||
*codegenScope, | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.