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 1 commit
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
27 changes: 27 additions & 0 deletions aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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 @@ -287,6 +309,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 +335,7 @@ tasks.register<ExecRustBuildTool>("fixManifests") {
dependsOn("relocateRuntime")
dependsOn("relocateAwsRuntime")
dependsOn("relocateExamples")
dependsOn("relocateTests")
}

tasks.register<ExecRustBuildTool>("hydrateReadme") {
Expand Down Expand Up @@ -371,6 +397,7 @@ tasks.register("finalizeSdk") {
"relocateRuntime",
"relocateAwsRuntime",
"relocateExamples",
"relocateTests",
"generateIndexMd",
"fixManifests",
"generateVersionManifest",
Expand Down
55 changes: 39 additions & 16 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,55 @@ 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
examples +
rootTests.map(RootTest::manifestName)
).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