Skip to content

Commit

Permalink
Remove StubConfigCustomization test facility and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Nov 14, 2023
1 parent f40840d commit 6220b61
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@

package software.amazon.smithy.rustsdk

import SdkCodegenIntegrationTest
import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations
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.integrationTest
import software.amazon.smithy.rust.codegen.core.testutil.tokioTest

internal class CredentialProviderConfigTest {
@Test
fun `generates a valid config`() {
val codegenContext = awsTestCodegenContext()
validateConfigCustomizations(codegenContext, CredentialProviderConfig(codegenContext))
}

@Test
fun `configuring credentials provider at operation level should work`() {
awsSdkIntegrationTest(SdkCodegenIntegrationTest.model) { ctx, rustCrate ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@

package software.amazon.smithy.rustsdk

import SdkCodegenIntegrationTest
import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.testutil.testClientRustSettings
import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations
import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace
import software.amazon.smithy.rust.codegen.core.testutil.rustSettings
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.testutil.unitTest

internal class RegionProviderConfigTest {
@Test
fun `generates a valid config`() {
val project = TestWorkspace.testProject()
val codegenContext = awsTestCodegenContext(
settings = testClientRustSettings(
moduleName = project.rustSettings().moduleName,
runtimeConfig = AwsTestRuntimeConfig,
),
)
validateConfigCustomizations(codegenContext, RegionProviderConfig(codegenContext), project)
awsSdkIntegrationTest(SdkCodegenIntegrationTest.model) { _ctx, crate ->
crate.unitTest {
rustTemplate("let conf: Option<crate::Config> = None; let _reg: Option<crate::config::Region> = conf.and_then(|c|c.region().cloned());")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,29 @@ fun awsSdkIntegrationTest(
) =
clientIntegrationTest(
model,
IntegrationTestParams(
cargoCommand = "cargo test --features test-util behavior-version-latest",
runtimeConfig = AwsTestRuntimeConfig,
additionalSettings = ObjectNode.builder().withMember(
"customizationConfig",
ObjectNode.builder()
.withMember(
"awsSdk",
ObjectNode.builder()
.withMember("generateReadme", false)
.withMember("integrationTestPath", "../sdk/integration-tests")
.build(),
).build(),
)
.withMember(
"codegen",
ObjectNode.builder()
.withMember("includeFluentClient", false)
.withMember("includeEndpointUrlConfig", false)
.build(),
).build(),
),
awsIntegrationTestParams(),
test = test,
)

fun awsIntegrationTestParams() = IntegrationTestParams(
cargoCommand = "cargo test --features test-util behavior-version-latest",
runtimeConfig = AwsTestRuntimeConfig,
additionalSettings = ObjectNode.builder().withMember(
"customizationConfig",
ObjectNode.builder()
.withMember(
"awsSdk",
ObjectNode.builder()
.withMember("generateReadme", false)
.withMember("integrationTestPath", "../sdk/integration-tests")
.build(),
).build(),
)
.withMember(
"codegen",
ObjectNode.builder()
.withMember("includeFluentClient", false)
.withMember("includeEndpointUrlConfig", false)
.build(),
).build(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal class EndpointConfigCustomization(
"SharedEndpointResolver" to epModule.resolve("SharedEndpointResolver"),
"StaticUriEndpointResolver" to epRuntimeModule.resolve("StaticUriEndpointResolver"),
"ServiceSpecificResolver" to codegenContext.serviceSpecificEndpointResolver(),
"IntoShared" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("shared::IntoShared"),
)

override fun section(section: ServiceConfig): Writable {
Expand Down Expand Up @@ -89,7 +90,7 @@ internal class EndpointConfigCustomization(
##[allow(deprecated)]
self.set_endpoint_resolver(
endpoint_url.map(|url| {
#{StaticUriEndpointResolver}::uri(url).into_shared()
#{IntoShared}::into_shared(#{StaticUriEndpointResolver}::uri(url))
})
);
self
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ fun TestWriterDelegator.clientRustSettings() =
moduleName = "test_${baseDir.toFile().nameWithoutExtension}",
codegenConfig = codegenConfig as ClientCodegenConfig,
)

fun TestWriterDelegator.clientCodegenContext(model: Model) = testClientCodegenContext(model, settings = clientRustSettings())
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
package software.amazon.smithy.rust.codegen.client.smithy.customizations

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginGenerator
import software.amazon.smithy.rust.codegen.client.testutil.clientRustSettings
import software.amazon.smithy.rust.codegen.client.testutil.stubConfigProject
import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer
import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer
import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.testutil.NamingObstacleCourseTestModels
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest
import software.amazon.smithy.rust.codegen.core.testutil.unitTest

internal class ResiliencyConfigCustomizationTest {
private val baseModel = """
Expand All @@ -37,18 +31,16 @@ internal class ResiliencyConfigCustomizationTest {

@Test
fun `generates a valid config`() {
val model = RecursiveShapeBoxer().transform(OperationNormalizer.transform(baseModel))
val project = TestWorkspace.testProject(model, ClientCodegenConfig())
val codegenContext = testClientCodegenContext(model, settings = project.clientRustSettings())

stubConfigProject(codegenContext, ResiliencyConfigCustomization(codegenContext), project)
project.withModule(ClientRustModule.config) {
ServiceRuntimePluginGenerator(codegenContext).render(
this,
emptyList(),
)
clientIntegrationTest(NamingObstacleCourseTestModels.rustPreludeOperationsModel()) { _, crate ->
crate.unitTest("resiliency_fields") {
rustTemplate(
"""
let mut conf = crate::Config::builder();
conf.set_sleep_impl(None);
conf.set_retry_config(None);
""",
)
}
}
ResiliencyReExportCustomization(codegenContext).extras(project)
project.compileAndTest()
}
}
Loading

0 comments on commit 6220b61

Please sign in to comment.