Skip to content

Commit

Permalink
Verify places managing crates stabilities are in sync
Browse files Browse the repository at this point in the history
This commit addresses #3082 (comment)
  • Loading branch information
ysaito1001 committed Nov 6, 2023
1 parent 4db11f4 commit 4add629
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/CrateSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class Crate(val name: String, val versionPropertyName: String)

object CrateSet {
const val STABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.stable.version"
private const val UNSTABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.unstable.version"
const val UNSTABLE_VERSION_PROP_NAME = "smithy.rs.runtime.crate.unstable.version"

/*
* Crates marked as `STABLE_VERSION_PROP_NAME` should have the following package metadata in their `Cargo.toml`
Expand All @@ -29,7 +29,7 @@ object CrateSet {
Crate("aws-types", STABLE_VERSION_PROP_NAME),
)

private val SMITHY_RUNTIME_COMMON = listOf(
val SMITHY_RUNTIME_COMMON = listOf(
Crate("aws-smithy-async", STABLE_VERSION_PROP_NAME),
Crate("aws-smithy-checksums", UNSTABLE_VERSION_PROP_NAME),
Crate("aws-smithy-client", UNSTABLE_VERSION_PROP_NAME),
Expand All @@ -49,7 +49,7 @@ object CrateSet {

val AWS_SDK_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON

private val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + listOf(
val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + listOf(
Crate("aws-smithy-http-server", UNSTABLE_VERSION_PROP_NAME),
Crate("aws-smithy-http-server-python", UNSTABLE_VERSION_PROP_NAME),
Crate("aws-smithy-http-server-typescript", UNSTABLE_VERSION_PROP_NAME),
Expand Down
72 changes: 72 additions & 0 deletions buildSrc/src/test/kotlin/CrateSetTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import CrateSet.AWS_SDK_RUNTIME
import CrateSet.SERVER_SMITHY_RUNTIME
import CrateSet.SMITHY_RUNTIME_COMMON
import CrateSet.STABLE_VERSION_PROP_NAME
import CrateSet.UNSTABLE_VERSION_PROP_NAME
import com.moandjiezana.toml.Toml
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.io.File
import java.util.logging.Logger

class CrateSetTest {
private val logger: Logger = Logger.getLogger("CrateSetTest")

/*
* Checks whether `versionPropertyName` for a system under test, i.e. `Crate` in `CrateSet.kt`,
* matches what `package.metadata.smithy-rs-release-tooling` says in the `Cargo.toml`
* for the corresponding crate.
*/
private fun sutStabilityMatchesManifestStability(versionPropertyName: String, stabilityInManifest: Boolean) {
when (stabilityInManifest) {
true -> assertEquals(STABLE_VERSION_PROP_NAME, versionPropertyName)
false -> assertEquals(UNSTABLE_VERSION_PROP_NAME, versionPropertyName)
}
}

/*
* Checks whether each element in `crateSet` specifies the correct `versionPropertyName` according to
* what `package.metadata.smithy-rs-release-tooling` says in the `Cargo.toml` for the corresponding crate,
* located at `relativePathToRustRuntime`.
*
* If `package.metadata.smithy-rs-release-tooling` does not exist in a `Cargo.toml`, the implementation
* will treat that crate as unstable.
*/
private fun crateSetStabilitiesMatchManifestStabilities(crateSet: List<Crate>, relativePathToRustRuntime: String) {
crateSet.forEach {
val path = "$relativePathToRustRuntime/${it.name}/Cargo.toml"
val contents = File(path).readText()
val manifest = try {
Toml().read(contents)
} catch (e: java.lang.IllegalStateException) {
// Currently, `aws-sigv4` cannot be read as a `TOML` because of the following error:
// Invalid table definition on line 54: [target.'cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))'.dev-dependencies]]
logger.info("failed to read ${it.name} as TOML: $e")
Toml()
}
manifest.getTable("package.metadata.smithy-rs-release-tooling")?.entrySet()?.map { entry ->
sutStabilityMatchesManifestStability(it.versionPropertyName, entry.value as Boolean)
} ?: sutStabilityMatchesManifestStability(it.versionPropertyName, false)
}
}

@Test
fun `aws runtime stabilities should match those in manifest files`() {
crateSetStabilitiesMatchManifestStabilities(AWS_SDK_RUNTIME, "../aws/rust-runtime")
}

@Test
fun `common smithy runtime stabilities should match those in manifest files`() {
crateSetStabilitiesMatchManifestStabilities(SMITHY_RUNTIME_COMMON, "../rust-runtime")
}

@Test
fun `server smithy runtime stabilities should match those in manifest files`() {
crateSetStabilitiesMatchManifestStabilities(SERVER_SMITHY_RUNTIME, "../rust-runtime")
}
}

0 comments on commit 4add629

Please sign in to comment.