Skip to content

Commit 44dfed5

Browse files
committed
PR feedback
1 parent d3abcca commit 44dfed5

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/smoketests/SmokeTestsRunnerGenerator.kt

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import software.amazon.smithy.codegen.core.Symbol
44
import software.amazon.smithy.kotlin.codegen.core.*
55
import software.amazon.smithy.kotlin.codegen.integration.SectionId
66
import software.amazon.smithy.kotlin.codegen.integration.SectionKey
7-
import software.amazon.smithy.kotlin.codegen.model.expectShape
87
import software.amazon.smithy.kotlin.codegen.model.getTrait
98
import software.amazon.smithy.kotlin.codegen.model.hasTrait
109
import software.amazon.smithy.kotlin.codegen.model.isStringEnumShape
1110
import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointParametersGenerator
1211
import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointProviderGenerator
1312
import software.amazon.smithy.kotlin.codegen.rendering.protocol.stringToNumber
14-
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.ClientConfig.EndpointParams
15-
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.ClientConfig.EndpointProvider
16-
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.ClientConfig.Name
17-
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.ClientConfig.Value
13+
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.ClientConfig.EndpointParams
14+
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.ClientConfig.EndpointProvider
15+
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.ClientConfig.Name
16+
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.ClientConfig.Value
1817
import software.amazon.smithy.kotlin.codegen.rendering.util.format
1918
import software.amazon.smithy.kotlin.codegen.utils.dq
2019
import software.amazon.smithy.kotlin.codegen.utils.toCamelCase
@@ -26,6 +25,32 @@ import software.amazon.smithy.smoketests.traits.SmokeTestCase
2625
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
2726
import kotlin.jvm.optionals.getOrNull
2827

28+
// Section IDs
29+
object AdditionalEnvironmentVariables : SectionId
30+
object DefaultClientConfig : SectionId
31+
object HttpEngineOverride : SectionId
32+
object ServiceFilter : SectionId
33+
object SkipTags : SectionId
34+
object ClientConfig : SectionId {
35+
val Name: SectionKey<String> = SectionKey("aws.smithy.kotlin#SmokeTestClientConfigName")
36+
val Value: SectionKey<String> = SectionKey("aws.smithy.kotlin#SmokeTestClientConfigValue")
37+
val EndpointProvider: SectionKey<Symbol> = SectionKey("aws.smithy.kotlin#SmokeTestEndpointProvider")
38+
val EndpointParams: SectionKey<Symbol> = SectionKey("aws.smithy.kotlin#SmokeTestClientEndpointParams")
39+
}
40+
41+
/**
42+
* Env var for smoke test runners.
43+
* Should be a comma-delimited list of strings that correspond to tags on the test cases.
44+
* If a test case is tagged with one of the tags indicated by SMOKE_TEST_SKIP_TAGS, it MUST be skipped by the smoke test runner.
45+
*/
46+
const val SKIP_TAGS = "SMOKE_TEST_SKIP_TAGS"
47+
48+
/**
49+
* Env var for smoke test runners.
50+
* Should be a comma-separated list of service identifiers to test.
51+
*/
52+
const val SERVICE_FILTER = "SMOKE_TEST_SERVICE_IDS"
53+
2954
/**
3055
* Renders smoke tests runner for a service
3156
*/
@@ -172,7 +197,8 @@ class SmokeTestsRunnerGenerator(
172197
testCase.operationParameters.forEach { param ->
173198
val paramName = param.key.value.toCamelCase()
174199
writer.writeInline("#L = ", paramName)
175-
renderOperationParameter(paramName, param.value, paramsToShapes, testCase)
200+
val paramShape = paramsToShapes[paramName] ?: throw IllegalArgumentException("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
201+
renderOperationParameter(paramName, param.value, paramShape, testCase)
176202
}
177203
}
178204

@@ -206,11 +232,9 @@ class SmokeTestsRunnerGenerator(
206232
private fun renderOperationParameter(
207233
paramName: String,
208234
node: Node,
209-
shapes: Map<String, Shape>,
235+
shape: Shape,
210236
testCase: SmokeTestCase,
211-
shapeOverride: Shape? = null,
212237
) {
213-
val shape = shapeOverride ?: shapes[paramName] ?: throw Exception("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
214238
when {
215239
// String enum
216240
node is StringNode && shape.isStringEnumShape -> {
@@ -232,17 +256,17 @@ class SmokeTestsRunnerGenerator(
232256
writer.withBlock("#T {", "}", shapeSymbol) {
233257
node.members.forEach { member ->
234258
val memberName = member.key.value.toCamelCase()
235-
val memberShape = shape.allMembers[member.key.value] ?: throw Exception("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
259+
val memberShape = shape.allMembers[member.key.value] ?: throw IllegalArgumentException("Unable to find shape for operation parameter '$paramName' in smoke test '${testCase.functionName}'.")
236260
writer.writeInline("#L = ", memberName)
237-
renderOperationParameter(memberName, member.value, mapOf(memberName to memberShape), testCase)
261+
renderOperationParameter(memberName, member.value, memberShape, testCase)
238262
}
239263
}
240264
}
241265
// List
242266
node is ArrayNode && shape is CollectionShape -> {
243267
writer.withBlock("listOf(", ")") {
244268
node.elements.forEach { element ->
245-
renderOperationParameter(paramName, element, mapOf(), testCase, model.expectShape(shape.member.target))
269+
renderOperationParameter(paramName, element, model.expectShape(shape.member.target), testCase)
246270
writer.write(",")
247271
}
248272
}
@@ -322,19 +346,6 @@ class SmokeTestsRunnerGenerator(
322346
private val SmokeTestCase.clientConfig: MutableMap<StringNode, Node>?
323347
get() = this.vendorParams.get().members
324348

325-
// Section IDs
326-
object AdditionalEnvironmentVariables : SectionId
327-
object DefaultClientConfig : SectionId
328-
object HttpEngineOverride : SectionId
329-
object ServiceFilter : SectionId
330-
object SkipTags : SectionId
331-
object ClientConfig : SectionId {
332-
val Name: SectionKey<String> = SectionKey("aws.smithy.kotlin#SmokeTestClientConfigName")
333-
val Value: SectionKey<String> = SectionKey("aws.smithy.kotlin#SmokeTestClientConfigValue")
334-
val EndpointProvider: SectionKey<Symbol> = SectionKey("aws.smithy.kotlin#SmokeTestEndpointProvider")
335-
val EndpointParams: SectionKey<Symbol> = SectionKey("aws.smithy.kotlin#SmokeTestClientEndpointParams")
336-
}
337-
338349
// Constants
339350
private val model = ctx.model
340351
private val settings = ctx.settings
@@ -343,16 +354,3 @@ class SmokeTestsRunnerGenerator(
343354
private val service = symbolProvider.toSymbol(model.expectShape(settings.service))
344355
private val operations = model.topDownOperations(settings.service).filter { it.hasTrait<SmokeTestsTrait>() }
345356
}
346-
347-
/**
348-
* Env var for smoke test runners.
349-
* Should be a comma-delimited list of strings that correspond to tags on the test cases.
350-
* If a test case is tagged with one of the tags indicated by SMOKE_TEST_SKIP_TAGS, it MUST be skipped by the smoke test runner.
351-
*/
352-
const val SKIP_TAGS = "SMOKE_TEST_SKIP_TAGS"
353-
354-
/**
355-
* Env var for smoke test runners.
356-
* Should be a comma-separated list of service identifiers to test.
357-
*/
358-
const val SERVICE_FILTER = "SMOKE_TEST_SERVICE_IDS"

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/util/Node.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ fun Node.format(): String = when (this) {
2323
is ObjectNode -> stringMap.entries.joinToString(", ", "mapOf(", ")") { (key, value) ->
2424
"${key.dq()} to ${value.format()}"
2525
}
26-
else -> throw Exception("Unexpected node type: $this")
26+
else -> throw IllegalStateException("Unexpected node type: $this")
2727
}

0 commit comments

Comments
 (0)