-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
597 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
...dk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/testing/SmokeTestTraits.kt
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,27 @@ | ||
package aws.sdk.kotlin.codegen.model.traits.testing | ||
|
||
import software.amazon.smithy.model.node.ObjectNode | ||
import software.amazon.smithy.model.shapes.ShapeId | ||
import software.amazon.smithy.model.traits.AnnotationTrait | ||
|
||
/** | ||
* Indicates the annotated service should always return a failed response. | ||
* IMPORTANT: This trait is intended for use in integration or E2E tests only, not in real-life smoke tests that run | ||
* against a service endpoint. | ||
*/ | ||
class TestFailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { | ||
companion object { | ||
val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#failedResponseTrait") | ||
} | ||
} | ||
|
||
/** | ||
* Indicates the annotated service should always return a success response. | ||
* IMPORTANT: This trait is intended for use in integration or E2E tests only, not in real-life smoke tests that run | ||
* against a service endpoint. | ||
*/ | ||
class TestSuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { | ||
companion object { | ||
val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#successResponseTrait") | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...n/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt
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,45 @@ | ||
package aws.sdk.kotlin.codegen.smoketests | ||
|
||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriter | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding | ||
import software.amazon.smithy.kotlin.codegen.model.hasTrait | ||
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars | ||
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig | ||
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault | ||
import software.amazon.smithy.kotlin.codegen.utils.topDownOperations | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait | ||
|
||
/** | ||
* Adds AWS region support to smoke tests | ||
*/ | ||
class SmokeTestsCodegenRegionIntegration : KotlinIntegration { | ||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = | ||
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() } | ||
|
||
override val sectionWriters: List<SectionWriterBinding> | ||
get() = listOf( | ||
SectionWriterBinding(SmokeTestAdditionalEnvVars, envVars), | ||
SectionWriterBinding(SmokeTestDefaultConfig, region), | ||
SectionWriterBinding(SmokeTestRegionDefault, regionDefault), | ||
) | ||
|
||
private val envVars = SectionWriter { writer, _ -> | ||
writer.write( | ||
"private val regionOverride = #T.System.getenv(#S)", | ||
RuntimeTypes.Core.Utils.PlatformProvider, | ||
"AWS_SMOKE_TEST_REGION", | ||
) | ||
} | ||
|
||
private val region = SectionWriter { writer, _ -> | ||
writer.write("region = regionOverride") | ||
} | ||
|
||
private val regionDefault = SectionWriter { writer, _ -> | ||
writer.write("regionOverride ?:") | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...in/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt
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,50 @@ | ||
package aws.sdk.kotlin.codegen.smoketests.testing | ||
|
||
import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait | ||
import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait | ||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes | ||
import software.amazon.smithy.kotlin.codegen.core.withBlock | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriter | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding | ||
import software.amazon.smithy.kotlin.codegen.model.expectShape | ||
import software.amazon.smithy.kotlin.codegen.model.hasTrait | ||
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride | ||
import software.amazon.smithy.kotlin.codegen.utils.topDownOperations | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait | ||
|
||
/** | ||
* Adds [TestFailedResponseTrait] support to smoke tests | ||
* IMPORTANT: This integration is intended for use in integration or E2E tests only, not in real-life smoke tests that run | ||
* against a service endpoint. | ||
*/ | ||
class SmokeTestFailHttpEngineIntegration : KotlinIntegration { | ||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = | ||
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() } && | ||
!model.expectShape<ServiceShape>(settings.service).hasTrait(TestSuccessResponseTrait.ID) && | ||
model.expectShape<ServiceShape>(settings.service).hasTrait(TestFailedResponseTrait.ID) | ||
|
||
override val sectionWriters: List<SectionWriterBinding> | ||
get() = listOf( | ||
SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), | ||
) | ||
|
||
private val httpClientOverride = SectionWriter { writer, _ -> | ||
writer.withBlock("httpClient = #T(", ")", RuntimeTypes.HttpTest.TestEngine) { | ||
withBlock("roundTripImpl = { _, request ->", "}") { | ||
write( | ||
"val resp = #T(#T.BadRequest, #T.Empty, #T.Empty)", | ||
RuntimeTypes.Http.Response.HttpResponse, | ||
RuntimeTypes.Http.StatusCode, | ||
RuntimeTypes.Http.Headers, | ||
RuntimeTypes.Http.HttpBody, | ||
) | ||
write("val now = #T.now()", RuntimeTypes.Core.Instant) | ||
write("#T(request, resp, now, now)", RuntimeTypes.Http.HttpCall) | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt
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,37 @@ | ||
package aws.sdk.kotlin.codegen.smoketests.testing | ||
|
||
import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait | ||
import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait | ||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriter | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding | ||
import software.amazon.smithy.kotlin.codegen.model.expectShape | ||
import software.amazon.smithy.kotlin.codegen.model.hasTrait | ||
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride | ||
import software.amazon.smithy.kotlin.codegen.utils.topDownOperations | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait | ||
|
||
/** | ||
* Adds [TestSuccessResponseTrait] support to smoke tests | ||
* IMPORTANT: This integration is intended for use in integration or E2E tests only, not in real-life smoke tests that run | ||
* against a service endpoint. | ||
*/ | ||
class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { | ||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = | ||
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() } && | ||
model.expectShape<ServiceShape>(settings.service).hasTrait(TestSuccessResponseTrait.ID) && | ||
!model.expectShape<ServiceShape>(settings.service).hasTrait(TestFailedResponseTrait.ID) | ||
|
||
override val sectionWriters: List<SectionWriterBinding> | ||
get() = listOf( | ||
SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), | ||
) | ||
|
||
private val httpClientOverride = SectionWriter { writer, _ -> | ||
writer.write("httpClient = #T()", RuntimeTypes.HttpTest.TestEngine) | ||
} | ||
} |
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
Oops, something went wrong.