Copy non-service integration tests into SDK root tests directory (#2255)

* Copy non-service integration tests into SDK root tests directory

For tests in `aws/sdk/integration-tests` that are not named after a
service module, copy them into the SDK's root `tests/` directory so that
they are run as part of CI on the entire SDK.

* Add missing fields to integration test manifests
* Remove tests from root workspace
* Explicitly exclude the root tests from the root workspace
This commit is contained in:
John DiSanti 2023-01-27 13:13:25 -08:00 committed by GitHub
parent 980b5c441c
commit 7ad342aabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 123 additions and 16 deletions

View File

@ -5,6 +5,7 @@
import aws.sdk.AwsServices
import aws.sdk.Membership
import aws.sdk.RootTest
import aws.sdk.discoverServices
import aws.sdk.docsLandingPage
import aws.sdk.parseMembership
@ -198,6 +199,28 @@ tasks.register("relocateExamples") {
outputs.dir(outputDir)
}
tasks.register("relocateTests") {
description = "relocate the root integration tests and rewrite path dependencies"
doLast {
if (awsServices.rootTests.isNotEmpty()) {
copy {
val testDir = projectDir.resolve("integration-tests")
from(testDir)
awsServices.rootTests.forEach { test ->
include(test.path.toRelativeString(testDir) + "/**")
}
into(outputDir.resolve("tests"))
exclude("**/target")
filter { line -> line.replace("build/aws-sdk/sdk/", "sdk/") }
}
}
}
for (test in awsServices.rootTests) {
inputs.dir(test.path)
}
outputs.dir(outputDir)
}
tasks.register<ExecRustBuildTool>("fixExampleManifests") {
description = "Adds dependency path and corrects version number of examples after relocation"
enabled = awsServices.examples.isNotEmpty()
@ -272,6 +295,8 @@ tasks.register<Copy>("relocateChangelog") {
fun generateCargoWorkspace(services: AwsServices): String {
return """
|[workspace]
|exclude = [${"\n"}${services.rootTests.map(RootTest::manifestName).joinToString(",\n") { "| \"$it\"" }}
|]
|members = [${"\n"}${services.allModules.joinToString(",\n") { "| \"$it\"" }}
|]
""".trimMargin()
@ -287,6 +312,9 @@ tasks.register("generateCargoWorkspace") {
if (awsServices.examples.isNotEmpty()) {
inputs.dir(projectDir.resolve("examples"))
}
for (test in awsServices.rootTests) {
inputs.dir(test.path)
}
outputs.file(outputDir.resolve("Cargo.toml"))
outputs.upToDateWhen { false }
}
@ -310,6 +338,7 @@ tasks.register<ExecRustBuildTool>("fixManifests") {
dependsOn("relocateRuntime")
dependsOn("relocateAwsRuntime")
dependsOn("relocateExamples")
dependsOn("relocateTests")
}
tasks.register<ExecRustBuildTool>("hydrateReadme") {
@ -371,6 +400,7 @@ tasks.register("finalizeSdk") {
"relocateRuntime",
"relocateAwsRuntime",
"relocateExamples",
"relocateTests",
"generateIndexMd",
"fixManifests",
"generateVersionManifest",

View File

@ -4,6 +4,9 @@ name = "dynamo-tests"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>", "Russell Cohen <rcoh@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -2,6 +2,9 @@
name = "ec2-tests"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
[dev-dependencies]
aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }

View File

@ -4,6 +4,9 @@ name = "glacier-tests"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "iam-tests"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "kms-tests"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -3,6 +3,9 @@ name = "lambda"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>", "Zelda Hessler <zhessler@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
[dev-dependencies]
async-stream = "0.3.0"

View File

@ -1,4 +1,3 @@
# This Cargo.toml is unused in generated code. It exists solely to enable these tests to compile in-situ
[package]
name = "no-default-features"
version = "0.1.0"
@ -8,6 +7,9 @@ These tests ensure that things will fail (or not fail) as expected
when default features are disabled for all SDK and runtime crates.
"""
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "polly-tests"
version = "0.1.0"
authors = ["John DiSanti <jdisanti@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "qldb-tests"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>", "Shing Lyu <shinglyu@amazon.com"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "s3-tests"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "s3control"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -4,6 +4,9 @@ name = "sts-tests"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -1,8 +1,12 @@
# This Cargo.toml is unused in generated code. It exists solely to enable these tests to compile in-situ
[package]
name = "transcribestreaming"
version = "0.1.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>", "John DiSanti <jdisanti@amazon.com>"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"
publish = false
[dev-dependencies]
async-stream = "0.3.0"

View File

@ -14,6 +14,11 @@ import software.amazon.smithy.model.traits.TitleTrait
import java.io.File
import kotlin.streams.toList
data class RootTest(
val path: File,
val manifestName: String,
)
class AwsServices(
private val project: Project,
services: List<AwsService>,
@ -23,37 +28,56 @@ class AwsServices(
val services: List<AwsService>
val moduleNames: Set<String> by lazy { services.map { it.module }.toSortedSet() }
init {
this.services = services.sortedBy { it.module }
}
val allModules: Set<String> by lazy {
(
services.map(AwsService::module).map { "sdk/$it" } +
CrateSet.AWS_SDK_SMITHY_RUNTIME.map { "sdk/$it" } +
CrateSet.AWS_SDK_RUNTIME.map { "sdk/$it" } +
examples
// Root tests should not be included since they can't be part of the root Cargo workspace
// in order to test differences in Cargo features.
).toSortedSet()
}
val examples: List<String> by lazy {
project.projectDir.resolve("examples")
.listFiles { file -> !file.name.startsWith(".") }.orEmpty().toList()
.filter { file ->
val cargoToml = File(file, "Cargo.toml")
if (cargoToml.exists()) {
val usedModules = cargoToml.readLines()
.map { line -> line.substringBefore('=').trim() }
.filter { line -> line.startsWith("aws-sdk-") }
.map { line -> line.substringAfter("aws-sdk-") }
.toSet()
moduleNames.containsAll(usedModules)
} else {
false
}
}
.filter { file -> manifestCompatibleWithGeneratedServices(file) }
.map { "examples/${it.name}" }
}
init {
this.services = services.sortedBy { it.module }
/**
* Tests in `aws/sdk/integration-tests` that are not named after a service module, and therefore,
* are not included in a service's `tests/` directory. These are to be included at the SDK root
* `tests/` directory for inclusion in CI.
*/
val rootTests: List<RootTest> by lazy {
project.projectDir.resolve("integration-tests")
.listFiles { file -> !file.name.startsWith(".") }.orEmpty().toList()
.filter { file -> !moduleNames.contains(file.name) && manifestCompatibleWithGeneratedServices(file) }
.map { file -> RootTest(file, "tests/${file.name}") }
}
/**
* Returns true if the Cargo manifest in the given path is compatible with the set of generated services.
*/
private fun manifestCompatibleWithGeneratedServices(path: File) =
File(path, "Cargo.toml").let { cargoToml ->
if (cargoToml.exists()) {
val usedModules = cargoToml.readLines()
.map { line -> line.substringBefore('=').trim() }
.filter { line -> line.startsWith("aws-sdk-") }
.map { line -> line.substringAfter("aws-sdk-") }
.toSet()
moduleNames.containsAll(usedModules)
} else {
false
}
}
}
/**

View File

@ -11,3 +11,10 @@ cd aws-sdk
sed -i '/"examples\//d' Cargo.toml
cargo test --all-features
for test_dir in tests/*; do
if [ -f "${test_dir}/Cargo.toml" ]; then
echo "#### Testing ${test_dir}..."
cargo test --all-features --manifest-path "${test_dir}/Cargo.toml"
fi
done

View File

@ -13,3 +13,10 @@ cd aws-sdk
sed -i '/"examples\//d' Cargo.toml
cargo check --all-targets --all-features
for test_dir in tests/*; do
if [ -f "${test_dir}/Cargo.toml" ]; then
echo "#### Checking ${test_dir}..."
cargo check --all-targets --all-features --manifest-path "${test_dir}/Cargo.toml"
fi
done