-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add clientIntegration test and fix event stream signing test * Update AWS Endpoint tests * Clean up more integration-style-tests * Delete unused test * Smithy upgrade * Set warnings & fix unit test
- Loading branch information
Showing
15 changed files
with
294 additions
and
248 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
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
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
104 changes: 104 additions & 0 deletions
104
...main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.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,104 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.testutil | ||
|
||
import software.amazon.smithy.build.PluginContext | ||
import software.amazon.smithy.build.SmithyBuildPlugin | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.node.ObjectNode | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin | ||
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator | ||
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext | ||
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig | ||
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate | ||
import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext | ||
import software.amazon.smithy.rust.codegen.core.testutil.printGeneratedFiles | ||
import software.amazon.smithy.rust.codegen.core.util.runCommand | ||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
/** | ||
* Run cargo test on a true, end-to-end, codegen product of a given model. | ||
* | ||
* For test purposes, additional codegen decorators can also be composed. | ||
*/ | ||
fun clientIntegrationTest( | ||
model: Model, | ||
addtionalDecorators: List<RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext>> = listOf(), | ||
addModuleToEventStreamAllowList: Boolean = false, | ||
service: String? = null, | ||
runtimeConfig: RuntimeConfig? = null, | ||
additionalSettings: ObjectNode = ObjectNode.builder().build(), | ||
test: (ClientCodegenContext, RustCrate) -> Unit, | ||
): Path { | ||
return codegenIntegrationTest( | ||
model, | ||
RustCodegenPlugin(), | ||
addtionalDecorators, | ||
addModuleToEventStreamAllowList = addModuleToEventStreamAllowList, | ||
service = service, | ||
runtimeConfig = runtimeConfig, | ||
additionalSettings = additionalSettings, | ||
test = test, | ||
) | ||
} | ||
|
||
/** | ||
* A Smithy BuildPlugin that accepts an additional decorator | ||
* | ||
* This exists to allow tests to easily customize the _real_ build without needing to list out customizations | ||
* or attempt to manually discover them from the path | ||
*/ | ||
abstract class DecoratableBuildPlugin<T, C : CodegenContext> : SmithyBuildPlugin { | ||
abstract fun executeWithDecorator( | ||
context: PluginContext, | ||
vararg decorator: RustCodegenDecorator<T, C>, | ||
) | ||
|
||
override fun execute(context: PluginContext) { | ||
executeWithDecorator(context) | ||
} | ||
} | ||
|
||
// TODO(https://github.com/awslabs/smithy-rs/issues/1864): move to core once CodegenDecorator is in core | ||
private fun <T, C : CodegenContext> codegenIntegrationTest( | ||
model: Model, | ||
buildPlugin: DecoratableBuildPlugin<T, C>, | ||
additionalDecorators: List<RustCodegenDecorator<T, C>>, | ||
additionalSettings: ObjectNode = ObjectNode.builder().build(), | ||
addModuleToEventStreamAllowList: Boolean = false, | ||
service: String? = null, | ||
runtimeConfig: RuntimeConfig? = null, | ||
overrideTestDir: File? = null, test: (C, RustCrate) -> Unit, | ||
): Path { | ||
val (ctx, testDir) = generatePluginContext( | ||
model, | ||
additionalSettings, | ||
addModuleToEventStreamAllowList, | ||
service, | ||
runtimeConfig, | ||
overrideTestDir, | ||
) | ||
|
||
val codegenDecorator = object : RustCodegenDecorator<T, C> { | ||
override val name: String = "Add tests" | ||
override val order: Byte = 0 | ||
override fun supportsCodegenContext(clazz: Class<out CodegenContext>): Boolean { | ||
// never discoverable on the classpath | ||
return false | ||
} | ||
|
||
override fun extras(codegenContext: C, rustCrate: RustCrate) { | ||
test(codegenContext, rustCrate) | ||
} | ||
} | ||
buildPlugin.executeWithDecorator(ctx, codegenDecorator, *additionalDecorators.toTypedArray()) | ||
ctx.fileManifest.printGeneratedFiles() | ||
"cargo test".runCommand(testDir, environment = mapOf("RUSTFLAGS" to "-D warnings")) | ||
return testDir | ||
} |
Oops, something went wrong.