Skip to content

Commit

Permalink
Cleanup, Clarity changes to test code in src
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Sep 25, 2024
1 parent 8aae6e4 commit 5687f7e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
package aws.sdk.kotlin.codegen

import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait
import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait
import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait
import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait
import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList
import software.amazon.smithy.kotlin.codegen.core.*
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
Expand Down Expand Up @@ -119,8 +119,8 @@ class GradleGenerator : KotlinIntegration {
* Generates a gradle task to run smoke tests
*/
private fun generateSmokeTestTask(writer: GradleWriter, ctx: CodegenContext) {
val hasSuccessResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(SuccessResponseTrait.ID)
val hasFailedResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(FailedResponseTrait.ID)
val hasSuccessResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(TestSuccessResponseTrait.ID)
val hasFailedResponseTrait = ctx.model.expectShape<ServiceShape>(ctx.settings.service).hasTrait(TestFailedResponseTrait.ID)
val inTestingEnvironment = hasFailedResponseTrait || hasSuccessResponseTrait

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package aws.sdk.kotlin.codegen.model.traits
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 FailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) {
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 SuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) {
class TestSuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) {
companion object {
val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#successResponseTrait")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
*/
class SmokeTestsCodegenRegionIntegration : KotlinIntegration {
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() } && settings.sdkId !in smokeTestDenyList
model.topDownOperations(settings.service).any { it.hasTrait<SmokeTestsTrait>() }

override val sectionWriters: List<SectionWriterBinding>
get() = listOf(
Expand All @@ -29,8 +29,8 @@ class SmokeTestsCodegenRegionIntegration : KotlinIntegration {

private val envVars = SectionWriter { writer, _ ->
writer.write(
"private val regionOverride = #T(#S)",
RuntimeTypes.Core.SmokeTests.getEnv,
"private val regionOverride = #T.System.getenv(#S)",
RuntimeTypes.Core.Utils.PlatformProvider,
"AWS_SMOKE_TEST_REGION",
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aws.sdk.kotlin.codegen.smoketests
package aws.sdk.kotlin.codegen.smoketests.testing

import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait
import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait
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
Expand All @@ -17,14 +17,15 @@ import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait

/**
* Adds [FailedResponseTrait] support to smoke tests
* 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>() } &&
settings.sdkId !in smokeTestDenyList &&
!model.expectShape<ServiceShape>(settings.service).hasTrait(SuccessResponseTrait.ID) &&
model.expectShape<ServiceShape>(settings.service).hasTrait(FailedResponseTrait.ID)
!model.expectShape<ServiceShape>(settings.service).hasTrait(TestSuccessResponseTrait.ID) &&
model.expectShape<ServiceShape>(settings.service).hasTrait(TestFailedResponseTrait.ID)

override val sectionWriters: List<SectionWriterBinding>
get() = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aws.sdk.kotlin.codegen.smoketests
package aws.sdk.kotlin.codegen.smoketests.testing

import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait
import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait
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
Expand All @@ -16,14 +16,15 @@ import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait

/**
* Adds [SuccessResponseTrait] support to smoke tests
* 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>() } &&
settings.sdkId !in smokeTestDenyList &&
model.expectShape<ServiceShape>(settings.service).hasTrait(SuccessResponseTrait.ID) &&
!model.expectShape<ServiceShape>(settings.service).hasTrait(FailedResponseTrait.ID)
model.expectShape<ServiceShape>(settings.service).hasTrait(TestSuccessResponseTrait.ID) &&
!model.expectShape<ServiceShape>(settings.service).hasTrait(TestFailedResponseTrait.ID)

override val sectionWriters: List<SectionWriterBinding>
get() = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration
aws.sdk.kotlin.codegen.BusinessMetricsIntegration
aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration
aws.sdk.kotlin.codegen.smoketests.SmokeTestsCodegenRegionIntegration
aws.sdk.kotlin.codegen.smoketests.SmokeTestSuccessHttpEngineIntegration
aws.sdk.kotlin.codegen.smoketests.SmokeTestFailHttpEngineIntegration
aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestSuccessHttpEngineIntegration
aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestFailHttpEngineIntegration

0 comments on commit 5687f7e

Please sign in to comment.