Skip to content

Commit 45f2711

Browse files
jdisantiZelda Hessler
andauthored
Fix protocol tests against the orchestrator (#2768)
This PR fixes the protocol tests in orchestrator mode, and adds `--all-targets` to the orchestrator CI checks. ---- _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: Zelda Hessler <zhessler@amazon.com>
1 parent 988eb61 commit 45f2711

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani
1717
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.FuturesUtil
1818
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.HdrHistogram
1919
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Hound
20+
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.HttpBody
2021
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.SerdeJson
2122
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.Smol
2223
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TempFile
@@ -122,6 +123,7 @@ class S3TestDependencies(private val codegenContext: ClientCodegenContext) : Lib
122123
addDependency(BytesUtils.toDevDependency())
123124
addDependency(FastRand.toDevDependency())
124125
addDependency(HdrHistogram)
126+
addDependency(HttpBody.toDevDependency())
125127
addDependency(Smol)
126128
addDependency(TempFile)
127129
addDependency(TracingAppender)

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class DefaultProtocolTestGenerator(
321321
writeInline("let expected_output =")
322322
instantiator.render(this, expectedShape, testCase.params)
323323
write(";")
324-
write("let http_response = #T::new()", RuntimeType.HttpResponseBuilder)
324+
write("let mut http_response = #T::new()", RuntimeType.HttpResponseBuilder)
325325
testCase.headers.forEach { (key, value) ->
326326
writeWithNoFormatting(".header(${key.dq()}, ${value.dq()})")
327327
}
@@ -360,7 +360,9 @@ class DefaultProtocolTestGenerator(
360360
let de = #{OperationDeserializer};
361361
let parsed = de.deserialize_streaming(&mut http_response);
362362
let parsed = parsed.unwrap_or_else(|| {
363-
let http_response = http_response.map(|body|#{copy_from_slice}(body.bytes().unwrap()));
363+
let http_response = http_response.map(|body| {
364+
#{SdkBody}::from(#{copy_from_slice}(body.bytes().unwrap()))
365+
});
364366
de.deserialize_nonstreaming(&http_response)
365367
});
366368
""",
@@ -369,20 +371,34 @@ class DefaultProtocolTestGenerator(
369371
"copy_from_slice" to RuntimeType.Bytes.resolve("copy_from_slice"),
370372
"ResponseDeserializer" to CargoDependency.smithyRuntimeApi(codegenContext.runtimeConfig).toType()
371373
.resolve("client::orchestrator::ResponseDeserializer"),
374+
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig),
372375
)
373376
}
374377
if (expectedShape.hasTrait<ErrorTrait>()) {
375378
val errorSymbol = codegenContext.symbolProvider.symbolForOperationError(operationShape)
376379
val errorVariant = codegenContext.symbolProvider.toSymbol(expectedShape).name
377380
rust("""let parsed = parsed.expect_err("should be error response");""")
381+
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
382+
rustTemplate(
383+
"""let parsed: &#{Error} = parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();""",
384+
"Error" to codegenContext.symbolProvider.symbolForOperationError(operationShape),
385+
)
386+
}
378387
rustBlock("if let #T::$errorVariant(parsed) = parsed", errorSymbol) {
379388
compareMembers(expectedShape)
380389
}
381390
rustBlock("else") {
382391
rust("panic!(\"wrong variant: Got: {:?}. Expected: {:?}\", parsed, expected_output);")
383392
}
384393
} else {
385-
rust("let parsed = parsed.unwrap();")
394+
if (codegenContext.smithyRuntimeMode.defaultToMiddleware) {
395+
rust("let parsed = parsed.unwrap();")
396+
} else {
397+
rustTemplate(
398+
"""let parsed: #{Output} = *parsed.expect("should be successful response").downcast().unwrap();""",
399+
"Output" to codegenContext.symbolProvider.toSymbol(expectedShape),
400+
)
401+
}
386402
compareMembers(outputShape)
387403
}
388404
}

tools/ci-scripts/check-aws-sdk-orchestrator-impl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ cd aws/sdk/build/aws-sdk/sdk
4242
for service in "${services_that_compile[@]}"; do
4343
pushd "${service}"
4444
echo -e "${C_YELLOW}# Running 'cargo check --all-features' on '${service}'${C_RESET}"
45-
RUSTFLAGS="${RUSTFLAGS:-} --cfg aws_sdk_orchestrator_mode" cargo check --all-features
45+
RUSTFLAGS="${RUSTFLAGS:-} --cfg aws_sdk_orchestrator_mode" cargo check --all-features --all-targets
4646
popd
4747
done
4848

4949
for service in "${services_that_pass_tests[@]}"; do
5050
pushd "${service}"
5151
echo -e "${C_YELLOW}# Running 'cargo test --all-features' on '${service}'${C_RESET}"
52-
RUSTFLAGS="${RUSTFLAGS:-} --cfg aws_sdk_orchestrator_mode" cargo test --all-features --no-fail-fast
52+
RUSTFLAGS="${RUSTFLAGS:-} --cfg aws_sdk_orchestrator_mode" cargo test --all-features --all-targets --no-fail-fast
5353
popd
5454
done
5555

0 commit comments

Comments
 (0)