-
Notifications
You must be signed in to change notification settings - Fork 49
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
misc: add rules engine codegen tests #1459
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4729584
misc: add rules engine codegen tests
0marperez 7b73088
Use snapshot version of smithy kotlin
0marperez dbfb973
debugging: throw exception to see what metrics are strings
0marperez b15358b
debugging: remove exception
0marperez dacc345
Don't depend on snapshot version of smithy kotlin
0marperez bbafc3f
Use released version
0marperez a79aa1e
PR feedback
0marperez d3279aa
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez 91abbb6
Trigger CI
0marperez 4ddf8f7
smithy kotlin version bump
0marperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* 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 | ||
|
||
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 | ||
} | ||
|
||
val tests = listOf( | ||
Test("operationContextParams", "operationContextParams", file("operation-context-params.smithy")), | ||
) | ||
|
||
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) | ||
transforms = listOf( | ||
""" | ||
{ | ||
"name": "includeServices", | ||
"args": { | ||
"services": ["$testServiceShapeId"] | ||
} | ||
} | ||
""", | ||
) | ||
|
||
smithyKotlinPlugin { | ||
serviceShapeId = testServiceShapeId | ||
packageName = "aws.sdk.kotlin.test.${test.projectionName.lowercase()}" | ||
packageVersion = "1.0" | ||
buildSettings { | ||
generateFullProject = false | ||
generateDefaultBuildFiles = false | ||
optInAnnotations = listOf( | ||
"aws.smithy.kotlin.runtime.InternalApi", | ||
"aws.sdk.kotlin.runtime.InternalSdkApi", | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { | ||
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 --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this dependency list generated by? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's just manually written. I couldn't find anything that suggests it's code generated |
||
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 --> | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/codegen/rules-engine/operation-context-params.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
$version: "2.0" | ||
namespace aws.sdk.kotlin.test | ||
|
||
use aws.protocols#awsJson1_0 | ||
use smithy.rules#operationContextParams | ||
use smithy.rules#endpointRuleSet | ||
use aws.api#service | ||
|
||
@awsJson1_0 | ||
@service(sdkId: "OperationContextParamsTest") | ||
@endpointRuleSet( | ||
version: "1.0", | ||
parameters: { | ||
"ObjectKeys": { | ||
"type": "stringArray", | ||
"documentation": "A string array.", | ||
"required": true | ||
} | ||
}, | ||
rules: [ | ||
{ | ||
"type": "endpoint", | ||
"conditions": [], | ||
"endpoint": { | ||
"url": "https://static.endpoint" | ||
} | ||
} | ||
] | ||
) | ||
service TestService { | ||
operations: [DeleteObjects], | ||
version: "1" | ||
} | ||
|
||
@operationContextParams( | ||
ObjectKeys: { | ||
path: "Delete.Objects[*].[Key][]" | ||
} | ||
) | ||
operation DeleteObjects { | ||
input: DeleteObjectsRequest | ||
} | ||
|
||
structure DeleteObjectsRequest { | ||
Delete: Delete | ||
} | ||
|
||
structure Delete { | ||
Objects: ObjectIdentifierList | ||
} | ||
|
||
list ObjectIdentifierList { | ||
member: ObjectIdentifier | ||
} | ||
|
||
structure ObjectIdentifier { | ||
Key: String | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed most of this file is copy-pasted from elsewhere, is there any reason this needs to be a new module rather than in the existing codegen tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organization mostly, it didn't feel right to have this under
tests/codegen/event-stream
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see the codegen build scripts abstracted to cover both event streams and endpoint rules than copy-pasting the entire file, is that possible?