|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import aws.sdk.kotlin.gradle.codegen.dsl.generateSmithyProjections |
| 7 | +import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin |
| 8 | +import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionSrcDir |
| 9 | + |
| 10 | +plugins { |
| 11 | + alias(libs.plugins.kotlin.jvm) |
| 12 | + alias(libs.plugins.aws.kotlin.repo.tools.smithybuild) |
| 13 | +} |
| 14 | + |
| 15 | +description = "Smithy rules engine codegen integration test suite" |
| 16 | + |
| 17 | +data class Test( |
| 18 | + val projectionName: String, |
| 19 | + val protocolName: String, |
| 20 | + val modelTemplate: File, |
| 21 | +) { |
| 22 | + val model: File |
| 23 | + get() = layout.buildDirectory.file("$projectionName/model.smithy").get().asFile |
| 24 | +} |
| 25 | + |
| 26 | +val tests = listOf( |
| 27 | + Test("operationContextParams", "operationContextParams", file("operation-context-params.smithy")), |
| 28 | +) |
| 29 | + |
| 30 | +fun fillInModel(output: File, protocolName: String, template: File) { |
| 31 | + val input = template.readText() |
| 32 | + val opTraits = when (protocolName) { |
| 33 | + "restJson1", "restXml" -> """@http(method: "POST", uri: "/test-eventstream", code: 200)""" |
| 34 | + else -> "" |
| 35 | + } |
| 36 | + val replaced = input |
| 37 | + .replace("{protocol-name}", protocolName) |
| 38 | + .replace("{op-traits}", opTraits) |
| 39 | + |
| 40 | + output.parentFile.mkdirs() |
| 41 | + output.writeText(replaced) |
| 42 | +} |
| 43 | + |
| 44 | +val testServiceShapeId = "aws.sdk.kotlin.test#TestService" |
| 45 | +smithyBuild { |
| 46 | + tests.forEach { test -> |
| 47 | + |
| 48 | + projections.register(test.projectionName) { |
| 49 | + imports = listOf(test.model.absolutePath) |
| 50 | + transforms = listOf( |
| 51 | + """ |
| 52 | + { |
| 53 | + "name": "includeServices", |
| 54 | + "args": { |
| 55 | + "services": ["$testServiceShapeId"] |
| 56 | + } |
| 57 | + } |
| 58 | + """, |
| 59 | + ) |
| 60 | + |
| 61 | + smithyKotlinPlugin { |
| 62 | + serviceShapeId = testServiceShapeId |
| 63 | + packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}" |
| 64 | + packageVersion = "1.0" |
| 65 | + buildSettings { |
| 66 | + generateFullProject = false |
| 67 | + generateDefaultBuildFiles = false |
| 68 | + optInAnnotations = listOf( |
| 69 | + "aws.smithy.kotlin.runtime.InternalApi", |
| 70 | + "aws.sdk.kotlin.runtime.InternalSdkApi", |
| 71 | + ) |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +val codegen by configurations.getting |
| 79 | +dependencies { |
| 80 | + codegen(project(":codegen:aws-sdk-codegen")) |
| 81 | + codegen(libs.smithy.cli) |
| 82 | + codegen(libs.smithy.model) |
| 83 | +} |
| 84 | + |
| 85 | +tasks.generateSmithyBuild { |
| 86 | + doFirst { |
| 87 | + tests.forEach { test -> fillInModel(test.model, test.protocolName, test.modelTemplate) } |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +tasks.generateSmithyProjections { |
| 92 | + doFirst { |
| 93 | + // ensure the generated tests use the same version of the runtime as the aws aws-runtime |
| 94 | + val smithyKotlinRuntimeVersion = libs.versions.smithy.kotlin.runtime.version.get() |
| 95 | + System.setProperty("smithy.kotlin.codegen.clientRuntimeVersion", smithyKotlinRuntimeVersion) |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +val optinAnnotations = listOf( |
| 100 | + "kotlin.RequiresOptIn", |
| 101 | + "aws.smithy.kotlin.runtime.InternalApi", |
| 102 | + "aws.sdk.kotlin.runtime.InternalSdkApi", |
| 103 | +) |
| 104 | + |
| 105 | +kotlin.sourceSets.all { |
| 106 | + optinAnnotations.forEach { languageSettings.optIn(it) } |
| 107 | +} |
| 108 | + |
| 109 | +kotlin.sourceSets.getByName("test") { |
| 110 | + smithyBuild.projections.forEach { |
| 111 | + kotlin.srcDir(smithyBuild.smithyKotlinProjectionSrcDir(it.name)) |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { |
| 116 | + dependsOn(tasks.generateSmithyProjections) |
| 117 | + // generated clients have quite a few warnings |
| 118 | + kotlinOptions.allWarningsAsErrors = false |
| 119 | +} |
| 120 | + |
| 121 | +tasks.test { |
| 122 | + useJUnitPlatform() |
| 123 | + testLogging { |
| 124 | + events("passed", "skipped", "failed") |
| 125 | + showStandardStreams = true |
| 126 | + showStackTraces = true |
| 127 | + showExceptions = true |
| 128 | + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +dependencies { |
| 133 | + |
| 134 | + implementation(libs.kotlinx.coroutines.core) |
| 135 | + |
| 136 | + testImplementation(libs.kotlin.test) |
| 137 | + testImplementation(libs.kotlin.test.junit5) |
| 138 | + testImplementation(libs.kotlinx.coroutines.test) |
| 139 | + |
| 140 | + testImplementation(libs.smithy.kotlin.smithy.test) |
| 141 | + testImplementation(libs.smithy.kotlin.aws.signing.default) |
| 142 | + testImplementation(libs.smithy.kotlin.telemetry.api) |
| 143 | + |
| 144 | + // have to manually add all the dependencies of the generated client(s) |
| 145 | + // doing it this way (as opposed to doing what we do for protocol-tests) allows |
| 146 | + // the tests to work without a publish to maven-local step at the cost of maintaining |
| 147 | + // this set of dependencies manually |
| 148 | + // <-- BEGIN GENERATED DEPENDENCY LIST --> |
| 149 | + implementation(libs.bundles.smithy.kotlin.service.client) |
| 150 | + implementation(libs.smithy.kotlin.aws.event.stream) |
| 151 | + implementation(project(":aws-runtime:aws-http")) |
| 152 | + implementation(libs.smithy.kotlin.aws.json.protocols) |
| 153 | + implementation(libs.smithy.kotlin.serde.json) |
| 154 | + api(project(":aws-runtime:aws-config")) |
| 155 | + api(project(":aws-runtime:aws-core")) |
| 156 | + api(project(":aws-runtime:aws-endpoint")) |
| 157 | + // <-- END GENERATED DEPENDENCY LIST --> |
| 158 | +} |
0 commit comments