-
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.
Merge branch 'smithy-rs-release-0.56.x' into jdisanti-fix-sdkerror-re…
…export
- Loading branch information
Showing
3 changed files
with
128 additions
and
2 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
119 changes: 119 additions & 0 deletions
119
...k-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointBuiltInsDecoratorTest.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,119 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rustsdk | ||
|
||
import org.junit.jupiter.api.Test | ||
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 | ||
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest | ||
|
||
class EndpointBuiltInsDecoratorTest { | ||
private val endpointUrlModel = """ | ||
namespace test | ||
use aws.api#service | ||
use aws.auth#sigv4 | ||
use aws.protocols#restJson1 | ||
use smithy.rules#endpointRuleSet | ||
@service(sdkId: "dontcare") | ||
@restJson1 | ||
@sigv4(name: "dontcare") | ||
@auth([sigv4]) | ||
@endpointRuleSet({ | ||
"version": "1.0" | ||
"parameters": { | ||
"endpoint": { "required": false, "type": "string", "builtIn": "SDK::Endpoint" }, | ||
"region": { "required": false, "type": "String", "builtIn": "AWS::Region" }, | ||
} | ||
"rules": [ | ||
{ | ||
"type": "endpoint" | ||
"conditions": [ | ||
{"fn": "isSet", "argv": [{"ref": "endpoint"}]}, | ||
{"fn": "isSet", "argv": [{"ref": "region"}]} | ||
], | ||
"endpoint": { | ||
"url": "{endpoint}" | ||
"properties": { | ||
"authSchemes": [{"name": "sigv4","signingRegion": "{region}"}] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "endpoint" | ||
"conditions": [ | ||
{"fn": "isSet", "argv": [{"ref": "region"}]}, | ||
], | ||
"endpoint": { | ||
"url": "https://WRONG/" | ||
"properties": { | ||
"authSchemes": [{"name": "sigv4", "signingRegion": "{region}"}] | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
service TestService { | ||
version: "2023-01-01", | ||
operations: [SomeOperation] | ||
} | ||
structure SomeOutput { | ||
someAttribute: Long, | ||
someVal: String | ||
} | ||
@http(uri: "/SomeOperation", method: "GET") | ||
@optionalAuth | ||
operation SomeOperation { | ||
output: SomeOutput | ||
} | ||
""".asSmithyModel() | ||
|
||
@Test | ||
fun endpointUrlBuiltInWorksEndToEnd() { | ||
awsSdkIntegrationTest( | ||
endpointUrlModel, | ||
generateOrchestrator = true, | ||
) { codegenContext, rustCrate -> | ||
rustCrate.integrationTest("endpoint_url_built_in_works") { | ||
val module = codegenContext.moduleUseName() | ||
rustTemplate( | ||
""" | ||
use $module::{Config, Client, config::Region}; | ||
##[#{tokio}::test] | ||
async fn endpoint_url_built_in_works() { | ||
let connector = #{TestConnection}::new(vec![( | ||
http::Request::builder() | ||
.uri("https://RIGHT/SomeOperation") | ||
.body(#{SdkBody}::empty()) | ||
.unwrap(), | ||
http::Response::builder().status(200).body("").unwrap(), | ||
)]); | ||
let config = Config::builder() | ||
.http_connector(connector.clone()) | ||
.region(Region::new("us-east-1")) | ||
.endpoint_url("https://RIGHT") | ||
.build(); | ||
let client = Client::from_conf(config); | ||
dbg!(client.some_operation().send().await).expect("success"); | ||
connector.assert_requests_match(&[]); | ||
} | ||
""", | ||
"tokio" to CargoDependency.Tokio.toDevDependency().withFeature("rt").withFeature("macros").toType(), | ||
"TestConnection" to CargoDependency.smithyClient(codegenContext.runtimeConfig) | ||
.toDevDependency().withFeature("test-util").toType() | ||
.resolve("test_connection::TestConnection"), | ||
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), | ||
) | ||
} | ||
} | ||
} | ||
} |
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