Skip to content

Commit e61efbb

Browse files
committed
Checkpoint
1 parent a79aa1e commit e61efbb

File tree

7 files changed

+176
-18
lines changed

7 files changed

+176
-18
lines changed

tests/codegen/common.gradle.kts

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
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 = "AWS SDK for Kotlin codegen integration test suite" // TODO: Don't commonize
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( // TODO: Don't commonize
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+
}

tests/codegen/event-stream/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414

1515
description = "Event stream codegen integration test suite"
1616

17-
data class EventStreamTest(
17+
data class Test(
1818
val projectionName: String,
1919
val protocolName: String,
2020
val modelTemplate: File,
@@ -24,8 +24,8 @@ data class EventStreamTest(
2424
}
2525

2626
val tests = listOf(
27-
EventStreamTest("restJson1", "restJson1", file("event-stream-model-template.smithy")),
28-
EventStreamTest("awsJson11", "awsJson1_1", file("event-stream-initial-request-response.smithy")),
27+
Test("restJson1", "restJson1", file("event-stream-model-template.smithy")),
28+
Test("awsJson11", "awsJson1_1", file("event-stream-initial-request-response.smithy")),
2929
)
3030

3131
fun fillInModel(output: File, protocolName: String, template: File) {
@@ -42,7 +42,7 @@ fun fillInModel(output: File, protocolName: String, template: File) {
4242
output.writeText(replaced)
4343
}
4444

45-
val testServiceShapeId = "aws.sdk.kotlin.test.eventstream#TestService"
45+
val testServiceShapeId = "aws.sdk.kotlin.test#TestService"
4646
smithyBuild {
4747
tests.forEach { test ->
4848

@@ -61,7 +61,7 @@ smithyBuild {
6161

6262
smithyKotlinPlugin {
6363
serviceShapeId = testServiceShapeId
64-
packageName = "aws.sdk.kotlin.test.eventstream.${test.projectionName.lowercase()}"
64+
packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}"
6565
packageVersion = "1.0"
6666
buildSettings {
6767
generateFullProject = false

tests/codegen/event-stream/event-stream-initial-request-response.smithy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace aws.sdk.kotlin.test.eventstream
1+
namespace aws.sdk.kotlin.test
22

33
use aws.protocols#awsJson1_1
44
use aws.api#service

tests/codegen/event-stream/event-stream-model-template.smithy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace aws.sdk.kotlin.test.eventstream
1+
namespace aws.sdk.kotlin.test
22

33
use aws.protocols#{protocol-name}
44
use aws.api#service

tests/codegen/event-stream/src/test/kotlin/HttpEventStreamTests.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

66
import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
7-
import aws.sdk.kotlin.test.eventstream.restjson1.model.*
8-
import aws.sdk.kotlin.test.eventstream.restjson1.serde.deserializeTestStreamOpOperationBody
9-
import aws.sdk.kotlin.test.eventstream.restjson1.serde.serializeTestStreamOpOperationBody
7+
import aws.sdk.kotlin.test.restjson1.model.*
8+
import aws.sdk.kotlin.test.restjson1.serde.deserializeTestStreamOpOperationBody
9+
import aws.sdk.kotlin.test.restjson1.serde.serializeTestStreamOpOperationBody
1010
import aws.smithy.kotlin.runtime.InternalApi
1111
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
1212
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes

tests/codegen/event-stream/src/test/kotlin/RpcEventStreamTests.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55
import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
6-
import aws.sdk.kotlin.test.eventstream.awsjson11.model.MessageWithString
7-
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStream
8-
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStreamOperationWithInitialRequestResponseRequest
9-
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStreamOperationWithInitialRequestResponseResponse
10-
import aws.sdk.kotlin.test.eventstream.awsjson11.serde.deserializeTestStreamOperationWithInitialRequestResponseOperationBody
11-
import aws.sdk.kotlin.test.eventstream.awsjson11.serde.serializeTestStreamOperationWithInitialRequestResponseOperationBody
6+
import aws.sdk.kotlin.test.awsjson11.model.MessageWithString
7+
import aws.sdk.kotlin.test.awsjson11.model.TestStream
8+
import aws.sdk.kotlin.test.awsjson11.model.TestStreamOperationWithInitialRequestResponseRequest
9+
import aws.sdk.kotlin.test.awsjson11.model.TestStreamOperationWithInitialRequestResponseResponse
10+
import aws.sdk.kotlin.test.awsjson11.serde.deserializeTestStreamOperationWithInitialRequestResponseOperationBody
11+
import aws.sdk.kotlin.test.awsjson11.serde.serializeTestStreamOperationWithInitialRequestResponseOperationBody
1212
import aws.smithy.kotlin.runtime.InternalApi
1313
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
1414
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes

tests/codegen/rules-engine/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
alias(libs.plugins.aws.kotlin.repo.tools.smithybuild)
1313
}
1414

15-
description = "Smithy rules engine codegen integration test suite"
15+
description = "AWS SDK for Kotlin codegen integration test suite" // TODO: Don't commonize
1616

1717
data class Test(
1818
val projectionName: String,
@@ -23,7 +23,7 @@ data class Test(
2323
get() = layout.buildDirectory.file("$projectionName/model.smithy").get().asFile
2424
}
2525

26-
val tests = listOf(
26+
val tests = listOf( // TODO: Don't commonize
2727
Test("operationContextParams", "operationContextParams", file("operation-context-params.smithy")),
2828
)
2929

0 commit comments

Comments
 (0)