Productionize Integration Test Machinery (#15)

* Productionize Integration Test Machinery

smithy-build.json is now dynamically generated along with a Cargo.toml to facilitate easy adding of new integration tests.

* We don't need REPO_ROOT anymore
This commit is contained in:
Russell Cohen 2020-11-03 18:44:38 -05:00 committed by GitHub
parent 787d317850
commit 44720f4dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 34 deletions

View File

@ -80,11 +80,8 @@ jobs:
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 8 java-version: 8
- name: set REPO_ROOT
run: echo "REPO_ROOT=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: integration-tests - name: integration-tests
run: ./gradlew :codegen-test:test run: ./gradlew :codegen-test:test
# TODO: when the multi repo integration tests are merged, update this to glob all of them
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v2
name: Upload Codegen Output for inspection name: Upload Codegen Output for inspection
# Always upload the output even if the tests failed # Always upload the output even if the tests failed
@ -92,7 +89,8 @@ jobs:
with: with:
name: codegen-output name: codegen-output
path: | path: |
codegen-test/build/smithyprojections/codegen-test/source/rust-codegen/ codegen-test/build/smithyprojections/codegen-test/*/rust-codegen/
codegen-test/build/smithyprojections/codegen-test/Cargo.toml
!**/target !**/target
runtime-tests: runtime-tests:
name: Rust runtime tests name: Rust runtime tests

1
codegen-test/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
smithy-build.json

View File

@ -1,11 +1,8 @@
# Codegen Integration Test # Codegen Integration Test
This module defines an integration test of the code generation machinery. Models defined in `model` are built and generated into a Rust package. A `cargoCheck` Gradle task ensures that the generated Rust code compiles. This is added as a finalizer of the `test` task. This module defines an integration test of the code generation machinery. `.build.gradle.kts` will generate a `smithy-build.json` file as part of the build. The Smithy build plugin then invokes our codegen machinery and generates Rust crates.
The `test` task will run `cargo check` and `cargo clippy` to validate that the generated Rust compiles and is idiomatic.
## Usage ## Usage
``` ```
# Compile codegen, Regenerate Rust, compile: ../gradlew test
# REPO_ROOT allows the runtime deps to be specified properly:
REPO_ROOT=../ ../gradlew test
``` ```
The `smithy-build.json` configures the runtime dependencies to point directly to `../rust-runtime/*` via relative paths.

View File

@ -16,12 +16,77 @@ val smithyVersion: String by project
dependencies { dependencies {
implementation(project(":codegen")) implementation(project(":codegen"))
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
} }
data class CodegenTest(val service: String, val module: String)
val CodgenTests = listOf(
CodegenTest("com.amazonaws.dynamodb#DynamoDB_20120810", "dynamo"),
CodegenTest("com.amazonaws.ebs#Ebs", "ebs"),
CodegenTest("aws.protocoltests.json10#JsonRpc10", "json_rpc10")
)
fun generateSmithyBuild(tests: List<CodegenTest>): String {
val projections = tests.joinToString(",\n") {
"""
"${it.module}": {
"plugins": {
"rust-codegen": {
"runtimeConfig": {
"relativePath": "${rootProject.projectDir.absolutePath}/rust-runtime"
},
"service": "${it.service}",
"module": "${it.module}",
"moduleVersion": "0.0.1",
"build": {
"rootProject": true
}
}
}
}
""".trimIndent()
}
return """
{
"version": "1.0",
"projections": { $projections }
}
"""
}
task("generateSmithyBuild") {
description = "generate smithy-build.json"
doFirst {
projectDir.resolve("smithy-build.json").writeText(generateSmithyBuild(CodgenTests))
}
}
fun generateCargoWorkspace(tests: List<CodegenTest>): String {
return """
[workspace]
members = [
${tests.joinToString(",") { "\"${it.module}/rust-codegen\"" }}
]
""".trimIndent()
}
task("generateCargoWorkspace") {
description = "generate Cargo.toml workspace file"
doFirst {
buildDir.resolve("smithyprojections/codegen-test/Cargo.toml").writeText(generateCargoWorkspace(CodgenTests))
}
}
tasks["smithyBuildJar"].dependsOn("generateSmithyBuild")
tasks["build"].finalizedBy("generateCargoWorkspace")
tasks.register<Exec>("cargoCheck") { tasks.register<Exec>("cargoCheck") {
workingDir("build/smithyprojections/codegen-test/source/rust-codegen/") workingDir("build/smithyprojections/codegen-test/")
// disallow warnings // disallow warnings
environment("RUSTFLAGS", "-D warnings") environment("RUSTFLAGS", "-D warnings")
commandLine("cargo", "check") commandLine("cargo", "check")
@ -29,7 +94,7 @@ tasks.register<Exec>("cargoCheck") {
} }
tasks.register<Exec>("cargoClippy") { tasks.register<Exec>("cargoClippy") {
workingDir("build/smithyprojections/codegen-test/source/rust-codegen/") workingDir("build/smithyprojections/codegen-test/")
// disallow warnings // disallow warnings
environment("RUSTFLAGS", "-D warnings") environment("RUSTFLAGS", "-D warnings")
commandLine("cargo", "clippy") commandLine("cargo", "clippy")
@ -37,3 +102,7 @@ tasks.register<Exec>("cargoClippy") {
} }
tasks["test"].finalizedBy("cargoCheck", "cargoClippy") tasks["test"].finalizedBy("cargoCheck", "cargoClippy")
tasks["clean"].doFirst {
delete("smithy-build.json")
}

View File

@ -1,17 +0,0 @@
{
"version": "1.0",
"outputDirectory": "target",
"plugins": {
"rust-codegen": {
"runtimeConfig": {
"relativePath": "${REPO_ROOT}/rust-runtime"
},
"service": "com.amazonaws.ebs#Ebs",
"module": "weather",
"moduleVersion": "0.0.1",
"build": {
"rootProject": true
}
}
}
}

View File

@ -178,7 +178,8 @@ class SymbolVisitor(
} }
override fun mapShape(shape: MapShape): Symbol { override fun mapShape(shape: MapShape): Symbol {
require(shape.key.isStringShape) val target = model.expectShape(shape.key.target)
require(target.isStringShape) { "unexpected key shape: ${shape.key}: $target [keys must be strings]" }
val key = this.toSymbol(shape.key) val key = this.toSymbol(shape.key)
val value = this.toSymbol(shape.value) val value = this.toSymbol(shape.value)
return symbolBuilder(shape, RustType.HashMap(key.rustType(), value.rustType())).namespace( return symbolBuilder(shape, RustType.HashMap(key.rustType(), value.rustType())).namespace(

View File

@ -5,10 +5,6 @@
# #
set -e set -e
# Used by codegen-test/smithy-build.json
declare REPO_ROOT
REPO_ROOT="$(git rev-parse --show-toplevel)"
export REPO_ROOT
./gradlew test ./gradlew test
./gradlew ktlintFormat ./gradlew ktlintFormat
./gradlew ktlint ./gradlew ktlint