Skip to content

Commit

Permalink
update codegen integration tests to use test-util-latest and smithy-h…
Browse files Browse the repository at this point in the history
…ttp-client directly
  • Loading branch information
aajtodd committed Dec 11, 2024
1 parent 52e4d35 commit ecc7dd7
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ class EndpointBuiltInsDecoratorTest {
""",
"tokio" to CargoDependency.Tokio.toDevDependency().withFeature("rt").withFeature("macros").toType(),
"StaticReplayClient" to
CargoDependency.smithyRuntimeTestUtil(codegenContext.runtimeConfig).toType()
.resolve("client::http::test_util::StaticReplayClient"),
CargoDependency.smithyHttpClientTestUtil(codegenContext.runtimeConfig).toType()
.resolve("test_util::StaticReplayClient"),
"ReplayEvent" to
CargoDependency.smithyRuntimeTestUtil(codegenContext.runtimeConfig).toType()
.resolve("client::http::test_util::ReplayEvent"),
CargoDependency.smithyHttpClientTestUtil(codegenContext.runtimeConfig).toType()
.resolve("test_util::ReplayEvent"),
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package software.amazon.smithy.rustsdk

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
Expand Down Expand Up @@ -162,11 +163,11 @@ class SigV4AuthDecoratorTest {
"ByteStream" to RuntimeType.byteStream(rc),
"Credentials" to AwsRuntimeType.awsCredentialTypesTestUtil(rc).resolve("Credentials"),
"Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"),
"ReplayEvent" to RuntimeType.smithyRuntimeTestUtil(rc).resolve("ReplayEvent"),
"ReplayEvent" to CargoDependency.smithyHttpClientTestUtil(rc).toType().resolve("test_utiL::ReplayEvent"),
"Request" to RuntimeType.HttpRequest,
"Response" to RuntimeType.HttpResponse,
"SdkBody" to RuntimeType.sdkBody(rc),
"StaticReplayClient" to RuntimeType.smithyRuntimeTestUtil(rc).resolve("StaticReplayClient"),
"StaticReplayClient" to CargoDependency.smithyHttpClientTestUtil(rc).toType().resolve("test_util::StaticReplayClient"),
"tracing_subscriber" to RuntimeType.TracingSubscriber,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ServiceGenerator(
)
serviceConfigGenerator.render(this)

// Enable users to opt in to the `test-util` feature in the runtime crate
rustCrate.mergeFeature(TestUtilFeature.copy(deps = listOf("aws-smithy-runtime/test-util")))
// Enable users to opt in to the `test-util-latest` feature in the runtime crate
rustCrate.mergeFeature(TestUtilFeature.copy(deps = listOf("aws-smithy-runtime/test-util-latest")))

ServiceRuntimePluginGenerator(codegenContext)
.render(this, decorator.serviceRuntimePluginCustomizations(codegenContext, emptyList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class ClientProtocolTestGenerator(
""",
"capture_request" to
CargoDependency.smithyRuntimeTestUtil(rc).toType()
.resolve("client::http::test_util::capture_request"),
CargoDependency.smithyHttpClientTestUtil(rc).toType()
.resolve("test_util::capture_request"),
"config" to ClientRustModule.config,
"customParams" to customParams,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SensitiveOutputDecoratorTest {
.resolve("test_util::capture_test_logs::capture_test_logs"),
"capture_request" to RuntimeType.captureRequest(runtimeConfig),
"SdkBody" to RuntimeType.sdkBody(runtimeConfig),
"http_1x" to CargoDependency.Http1x.toType(),
)

private val model =
Expand Down Expand Up @@ -59,7 +60,7 @@ class SensitiveOutputDecoratorTest {
async fn redacting_sensitive_response_body() {
let (_logs, logs_rx) = #{capture_test_logs}();
let (http_client, _r) = #{capture_request}(Some(
http::Response::builder()
#{http_1x}::Response::builder()
.status(200)
.body(#{SdkBody}::from(""))
.unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ class EndpointsDecoratorTest {
}
""",
"NeverClient" to
CargoDependency.smithyRuntimeTestUtil(clientCodegenContext.runtimeConfig)
.toType().resolve("client::http::test_util::NeverClient"),
CargoDependency.smithyHttpClientTestUtil(clientCodegenContext.runtimeConfig)
.toType().resolve("test_util::NeverClient"),
"TokioSleep" to
CargoDependency.smithyAsync(clientCodegenContext.runtimeConfig)
.withFeature("rt-tokio").toType().resolve("rt::sleep::TokioSleep"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ internal class ConfigOverrideRuntimePluginGeneratorTest {
"AsyncSleep" to RuntimeType.smithyAsync(runtimeConfig).resolve("rt::sleep::AsyncSleep"),
"capture_request" to RuntimeType.captureRequest(runtimeConfig),
"NeverClient" to
CargoDependency.smithyRuntimeTestUtil(runtimeConfig).toType()
.resolve("client::http::test_util::NeverClient"),
CargoDependency.smithyHttpClientTestUtil(runtimeConfig).toType()
.resolve("test_util::NeverClient"),
"Timeout" to RuntimeType.smithyAsync(runtimeConfig).resolve("future::timeout::Timeout"),
"TokioSleep" to
CargoDependency.smithyAsync(runtimeConfig).withFeature("rt-tokio")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ internal class EndpointTraitBindingsTest {
}
let (http_client, _r) = capture_request(Some(
http::Response::builder()
#{http_1x}::Response::builder()
.status(200)
.body(SdkBody::from(""))
.unwrap(),
Expand Down Expand Up @@ -249,8 +249,9 @@ internal class EndpointTraitBindingsTest {
}
""",
"capture_request" to
CargoDependency.smithyRuntimeTestUtil(clientCodegenContext.runtimeConfig)
.toType().resolve("client::http::test_util::capture_request"),
CargoDependency.smithyHttpClientTestUtil(clientCodegenContext.runtimeConfig)
.toType().resolve("test_util::capture_request"),
"http_1x" to CargoDependency.Http1x.toType(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class CustomizableOperationGeneratorTest {
}
""",
"NeverClient" to
CargoDependency.smithyRuntimeTestUtil(codegenContext.runtimeConfig).toType()
.resolve("client::http::test_util::NeverClient"),
CargoDependency.smithyHttpClientTestUtil(codegenContext.runtimeConfig).toType()
.resolve("test_util::NeverClient"),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class FluentClientGeneratorTest {
}
""",
"NeverClient" to
CargoDependency.smithyRuntimeTestUtil(codegenContext.runtimeConfig).toType()
.resolve("client::http::test_util::NeverClient"),
CargoDependency.smithyHttpClientTestUtil(codegenContext.runtimeConfig).toType()
.resolve("test_util::NeverClient"),
)
}
}
Expand Down Expand Up @@ -116,8 +116,8 @@ class FluentClientGeneratorTest {
}
""",
"NeverClient" to
CargoDependency.smithyRuntimeTestUtil(codegenContext.runtimeConfig).toType()
.resolve("client::http::test_util::NeverClient"),
CargoDependency.smithyHttpClientTestUtil(codegenContext.runtimeConfig).toType()
.resolve("test_util::NeverClient"),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class AwsQueryCompatibleTest {
tokioTest("should_parse_code_and_type_fields") {
rustTemplate(
"""
let response = |_: http::Request<#{SdkBody}>| {
http::Response::builder()
let response = |_: #{http_1x}::Request<#{SdkBody}>| {
#{http_1x}::Response::builder()
.header(
"x-amzn-query-error",
http::HeaderValue::from_static("AWS.SimpleQueueService.NonExistentQueue;Sender"),
#{http_1x}::HeaderValue::from_static("AWS.SimpleQueueService.NonExistentQueue;Sender"),
)
.status(400)
.body(
Expand Down Expand Up @@ -107,8 +107,9 @@ class AwsQueryCompatibleTest {
*RuntimeType.preludeScope,
"SdkBody" to RuntimeType.sdkBody(context.runtimeConfig),
"infallible_client_fn" to
CargoDependency.smithyRuntimeTestUtil(context.runtimeConfig)
.toType().resolve("client::http::test_util::infallible_client_fn"),
CargoDependency.smithyHttpClientTestUtil(context.runtimeConfig)
.toType().resolve("test_util::infallible_client_fn"),
"http_1x" to CargoDependency.Http1x.toType(),
)
}
}
Expand All @@ -126,8 +127,8 @@ class AwsQueryCompatibleTest {
tokioTest("should_parse_code_from_payload") {
rustTemplate(
"""
let response = |_: http::Request<#{SdkBody}>| {
http::Response::builder()
let response = |_: #{http_1x}::Request<#{SdkBody}>| {
#{http_1x}::Response::builder()
.status(400)
.body(
#{SdkBody}::from(
Expand All @@ -152,8 +153,9 @@ class AwsQueryCompatibleTest {
*RuntimeType.preludeScope,
"SdkBody" to RuntimeType.sdkBody(context.runtimeConfig),
"infallible_client_fn" to
CargoDependency.smithyRuntimeTestUtil(context.runtimeConfig)
.toType().resolve("client::http::test_util::infallible_client_fn"),
CargoDependency.smithyHttpClientTestUtil(context.runtimeConfig)
.toType().resolve("test_util::infallible_client_fn"),
"http_1x" to CargoDependency.Http1x.toType(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fun InlineDependency.toType() = RuntimeType(module.fullyQualifiedPath(), this)

data class Feature(val name: String, val default: Boolean, val deps: List<String>)

val DEV_ONLY_FEATURES = setOf("test-util")
val DEV_ONLY_FEATURES = setOf("test-util", "test-util-latest")

/**
* A dependency on an internal or external Cargo crate
Expand Down Expand Up @@ -365,6 +365,9 @@ data class CargoDependency(

fun smithyHttpClient(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-client")

fun smithyHttpClientTestUtil(runtimeConfig: RuntimeConfig) =
smithyHttpClient(runtimeConfig).toDevDependency().withFeature("test-util")

fun smithyJson(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-json")

fun smithyProtocolTestHelpers(runtimeConfig: RuntimeConfig) =
Expand All @@ -377,7 +380,7 @@ data class CargoDependency(
.withFeature("client")

fun smithyRuntimeTestUtil(runtimeConfig: RuntimeConfig) =
smithyRuntime(runtimeConfig).toDevDependency().withFeature("test-util")
smithyRuntime(runtimeConfig).toDevDependency().withFeature("test-util-latest")

fun smithyRuntimeApi(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-runtime-api")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,8 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
return smithyTypes(runtimeConfig).resolve("date_time::Format::$timestampFormat")
}

fun smithyRuntimeTestUtil(runtimeConfig: RuntimeConfig) =
CargoDependency.smithyRuntimeTestUtil(runtimeConfig).toType().resolve("client::http::test_util")

fun captureRequest(runtimeConfig: RuntimeConfig) =
smithyRuntimeTestUtil(runtimeConfig).resolve("capture_request")
CargoDependency.smithyHttpClientTestUtil(runtimeConfig).toType().resolve("test_util::capture_request")

fun forInlineDependency(inlineDependency: InlineDependency) =
RuntimeType("crate::${inlineDependency.name}", inlineDependency)
Expand Down

0 comments on commit ecc7dd7

Please sign in to comment.