-
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 'main' into required-context-params
- Loading branch information
Showing
8 changed files
with
254 additions
and
115 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
102 changes: 102 additions & 0 deletions
102
aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionDecoratorTest.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,102 @@ | ||
/* | ||
* 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.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel | ||
import kotlin.io.path.readText | ||
|
||
class RegionDecoratorTest { | ||
private val modelWithoutRegionParamOrSigV4AuthScheme = """ | ||
namespace test | ||
use aws.api#service | ||
use aws.protocols#awsJson1_0 | ||
use smithy.rules#endpointRuleSet | ||
@awsJson1_0 | ||
@endpointRuleSet({ | ||
"version": "1.0", | ||
"rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }], | ||
"parameters": {} | ||
}) | ||
@service(sdkId: "dontcare") | ||
service TestService { version: "2023-01-01", operations: [SomeOperation] } | ||
structure SomeOutput { something: String } | ||
operation SomeOperation { output: SomeOutput } | ||
""".asSmithyModel() | ||
|
||
private val modelWithRegionParam = """ | ||
namespace test | ||
use aws.api#service | ||
use aws.protocols#awsJson1_0 | ||
use smithy.rules#endpointRuleSet | ||
@awsJson1_0 | ||
@endpointRuleSet({ | ||
"version": "1.0", | ||
"rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }], | ||
"parameters": { | ||
"Region": { "required": false, "type": "String", "builtIn": "AWS::Region" }, | ||
} | ||
}) | ||
@service(sdkId: "dontcare") | ||
service TestService { version: "2023-01-01", operations: [SomeOperation] } | ||
structure SomeOutput { something: String } | ||
operation SomeOperation { output: SomeOutput } | ||
""".asSmithyModel() | ||
|
||
private val modelWithSigV4AuthScheme = """ | ||
namespace test | ||
use aws.auth#sigv4 | ||
use aws.api#service | ||
use aws.protocols#awsJson1_0 | ||
use smithy.rules#endpointRuleSet | ||
@auth([sigv4]) | ||
@sigv4(name: "dontcare") | ||
@awsJson1_0 | ||
@endpointRuleSet({ | ||
"version": "1.0", | ||
"rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }], | ||
"parameters": {} | ||
}) | ||
@service(sdkId: "dontcare") | ||
service TestService { version: "2023-01-01", operations: [SomeOperation] } | ||
structure SomeOutput { something: String } | ||
operation SomeOperation { output: SomeOutput } | ||
""".asSmithyModel() | ||
|
||
@Test | ||
fun `models without region built-in params or SigV4 should not have configurable regions`() { | ||
val path = awsSdkIntegrationTest(modelWithoutRegionParamOrSigV4AuthScheme) { _, _ -> | ||
// it should generate and compile successfully | ||
} | ||
val configContents = path.resolve("src/config.rs").readText() | ||
assertFalse(configContents.contains("fn set_region(")) | ||
} | ||
|
||
@Test | ||
fun `models with region built-in params should have configurable regions`() { | ||
val path = awsSdkIntegrationTest(modelWithRegionParam) { _, _ -> | ||
// it should generate and compile successfully | ||
} | ||
val configContents = path.resolve("src/config.rs").readText() | ||
assertTrue(configContents.contains("fn set_region(")) | ||
} | ||
|
||
@Test | ||
fun `models with SigV4 should have configurable regions`() { | ||
val path = awsSdkIntegrationTest(modelWithSigV4AuthScheme) { _, _ -> | ||
// it should generate and compile successfully | ||
} | ||
val configContents = path.resolve("src/config.rs").readText() | ||
assertTrue(configContents.contains("fn set_region(")) | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
...smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGeneratorTest.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,66 @@ | ||
/* | ||
* 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.clientIntegrationTest | ||
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.smithy.RustCrate | ||
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel | ||
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest | ||
|
||
class CustomizableOperationGeneratorTest { | ||
val model = """ | ||
namespace com.example | ||
use aws.protocols#awsJson1_0 | ||
@awsJson1_0 | ||
service HelloService { | ||
operations: [SayHello], | ||
version: "1" | ||
} | ||
@optionalAuth | ||
operation SayHello { input: TestInput } | ||
structure TestInput { | ||
foo: String, | ||
} | ||
""".asSmithyModel() | ||
|
||
@Test | ||
fun `CustomizableOperation is send and sync`() { | ||
val test: (ClientCodegenContext, RustCrate) -> Unit = { codegenContext, rustCrate -> | ||
rustCrate.integrationTest("customizable_operation_is_send_and_sync") { | ||
val moduleName = codegenContext.moduleUseName() | ||
rustTemplate( | ||
""" | ||
fn check_send_and_sync<T: Send + Sync>(_: T) {} | ||
##[test] | ||
fn test() { | ||
let connector = #{TestConnection}::<#{SdkBody}>::new(Vec::new()); | ||
let config = $moduleName::Config::builder() | ||
.http_connector(connector.clone()) | ||
.endpoint_resolver("http://localhost:1234") | ||
.build(); | ||
let client = $moduleName::Client::from_conf(config); | ||
check_send_and_sync(client.say_hello().customize()); | ||
} | ||
""", | ||
"TestConnection" to CargoDependency.smithyClient(codegenContext.runtimeConfig) | ||
.toDevDependency() | ||
.withFeature("test-util").toType() | ||
.resolve("test_connection::TestConnection"), | ||
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), | ||
) | ||
} | ||
} | ||
clientIntegrationTest(model, test = test) | ||
} | ||
} |
Oops, something went wrong.