From 77f6ea5be9e899d19a0ca7fefce803be8c7556b1 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 19 Dec 2024 09:42:30 -0500 Subject: [PATCH] Refactor rules engine codegen tests --- tests/codegen/rules-engine/build.gradle.kts | 135 ++---------------- .../operation-context-params.smithy | 0 2 files changed, 13 insertions(+), 122 deletions(-) rename tests/codegen/rules-engine/{ => src/commonTest/resources}/operation-context-params.smithy (100%) diff --git a/tests/codegen/rules-engine/build.gradle.kts b/tests/codegen/rules-engine/build.gradle.kts index ef35526b380..b6242e9f17a 100644 --- a/tests/codegen/rules-engine/build.gradle.kts +++ b/tests/codegen/rules-engine/build.gradle.kts @@ -3,64 +3,37 @@ * SPDX-License-Identifier: Apache-2.0 */ -import aws.sdk.kotlin.gradle.codegen.dsl.generateSmithyProjections import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin -import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir +import aws.sdk.kotlin.shared.CodegenTest +import aws.sdk.kotlin.shared.Model -plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.aws.kotlin.repo.tools.smithybuild) -} - -description = "Smithy rules engine codegen integration test suite" - -data class Test( - val projectionName: String, - val protocolName: String, - val modelTemplate: File, -) { - val model: File - get() = layout.buildDirectory.file("$projectionName/model.smithy").get().asFile -} +description = "AWS SDK for Kotlin's rules engine codegen integration test suite" val tests = listOf( - Test("operationContextParams", "operationContextParams", file("operation-context-params.smithy")), + CodegenTest( + "operationContextParams", + Model("operation-context-params.smithy"), + "aws.sdk.kotlin.test#TestService", + ), ) -fun fillInModel(output: File, protocolName: String, template: File) { - val input = template.readText() - val opTraits = when (protocolName) { - "restJson1", "restXml" -> """@http(method: "POST", uri: "/test-eventstream", code: 200)""" - else -> "" - } - val replaced = input - .replace("{protocol-name}", protocolName) - .replace("{op-traits}", opTraits) - - output.parentFile.mkdirs() - output.writeText(replaced) -} - -val testServiceShapeId = "aws.sdk.kotlin.test#TestService" smithyBuild { tests.forEach { test -> - - projections.register(test.projectionName) { - imports = listOf(test.model.absolutePath) + projections.register(test.name) { + imports = listOf(layout.projectDirectory.file(test.model.path + test.model.fileName).asFile.absolutePath) transforms = listOf( """ { "name": "includeServices", "args": { - "services": ["$testServiceShapeId"] + "services": ["${test.serviceShapeId}"] } } """, ) - smithyKotlinPlugin { - serviceShapeId = testServiceShapeId - packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}" + serviceShapeId = test.serviceShapeId + packageName = "aws.sdk.kotlin.test.${test.name.lowercase()}" packageVersion = "1.0" buildSettings { generateFullProject = false @@ -74,85 +47,3 @@ smithyBuild { } } } - -val codegen by configurations.getting -dependencies { - codegen(project(":codegen:aws-sdk-codegen")) - codegen(libs.smithy.cli) - codegen(libs.smithy.model) -} - -tasks.generateSmithyBuild { - doFirst { - tests.forEach { test -> fillInModel(test.model, test.protocolName, test.modelTemplate) } - } -} - -tasks.generateSmithyProjections { - doFirst { - // ensure the generated tests use the same version of the runtime as the aws aws-runtime - val smithyKotlinRuntimeVersion = libs.versions.smithy.kotlin.runtime.version.get() - System.setProperty("smithy.kotlin.codegen.clientRuntimeVersion", smithyKotlinRuntimeVersion) - } -} - -val optinAnnotations = listOf( - "kotlin.RequiresOptIn", - "aws.smithy.kotlin.runtime.InternalApi", - "aws.sdk.kotlin.runtime.InternalSdkApi", -) - -kotlin.sourceSets.all { - optinAnnotations.forEach { languageSettings.optIn(it) } -} - -kotlin.sourceSets.getByName("test") { - smithyBuild.projections.forEach { - kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir(it.name)) - } -} - -tasks.withType { - dependsOn(tasks.generateSmithyProjections) - // generated clients have quite a few warnings - kotlinOptions.allWarningsAsErrors = false -} - -tasks.test { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") - showStandardStreams = true - showStackTraces = true - showExceptions = true - exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL - } -} - -dependencies { - - implementation(libs.kotlinx.coroutines.core) - - testImplementation(libs.kotlin.test) - testImplementation(libs.kotlin.test.junit5) - testImplementation(libs.kotlinx.coroutines.test) - - testImplementation(libs.smithy.kotlin.smithy.test) - testImplementation(libs.smithy.kotlin.aws.signing.default) - testImplementation(libs.smithy.kotlin.telemetry.api) - - // have to manually add all the dependencies of the generated client(s) - // doing it this way (as opposed to doing what we do for protocol-tests) allows - // the tests to work without a publish to maven-local step at the cost of maintaining - // this set of dependencies manually - // <-- BEGIN GENERATED DEPENDENCY LIST --> - implementation(libs.bundles.smithy.kotlin.service.client) - implementation(libs.smithy.kotlin.aws.event.stream) - implementation(project(":aws-runtime:aws-http")) - implementation(libs.smithy.kotlin.aws.json.protocols) - implementation(libs.smithy.kotlin.serde.json) - api(project(":aws-runtime:aws-config")) - api(project(":aws-runtime:aws-core")) - api(project(":aws-runtime:aws-endpoint")) - // <-- END GENERATED DEPENDENCY LIST --> -} diff --git a/tests/codegen/rules-engine/operation-context-params.smithy b/tests/codegen/rules-engine/src/commonTest/resources/operation-context-params.smithy similarity index 100% rename from tests/codegen/rules-engine/operation-context-params.smithy rename to tests/codegen/rules-engine/src/commonTest/resources/operation-context-params.smithy