Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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 }
}
Expand All @@ -310,6 +338,7 @@ tasks.register<ExecRustBuildTool>("fixManifests") {
dependsOn("relocateRuntime")
dependsOn("relocateAwsRuntime")
dependsOn("relocateExamples")
dependsOn("relocateTests")
}

tasks.register<ExecRustBuildTool>("hydrateReadme") {
Expand Down Expand Up @@ -371,6 +400,7 @@ tasks.register("finalizeSdk") {
"relocateRuntime",
"relocateAwsRuntime",
"relocateExamples",
"relocateTests",
"generateIndexMd",
"fixManifests",
"generateVersionManifest",
Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/dynamodb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/ec2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/glacier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/iam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/kms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion aws/sdk/integration-tests/no-default-features/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/polly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/qldbsession/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/s3control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions aws/sdk/integration-tests/sts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions aws/sdk/integration-tests/transcribestreaming/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
54 changes: 39 additions & 15 deletions buildSrc/src/main/kotlin/aws/sdk/ServiceLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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
}
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tools/ci-build/scripts/check-aws-sdk-services
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions tools/ci-build/scripts/check-only-aws-sdk-services
Original file line number Diff line number Diff line change
Expand Up @@ -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