Skip to content

Commit 408b3cf

Browse files
committed
Add test for exception logging
1 parent e2107d7 commit 408b3cf

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

tests/codegen/smoke-tests/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ plugins {
1717
val projections = listOf(
1818
Projection("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"),
1919
Projection("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"),
20+
Projection("exceptionService", "smoke-tests-exception.smithy", "smithy.kotlin.traits#ExceptionService"),
2021
)
2122

2223
configureProject()

tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class SmokeTestE2ETest {
2020
assertContains(smokeTestRunnerOutput, "ok FailureService FailuresTest - error expected from service")
2121
}
2222

23+
@Test
24+
fun exceptionService() {
25+
val smokeTestRunnerOutput = runSmokeTests("exceptionService", expectingFailure = true)
26+
27+
assertContains(smokeTestRunnerOutput, "not ok ExceptionService ExceptionTest - no error expected from service")
28+
assertContains(smokeTestRunnerOutput, "#aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsFailureException: Smoke test failed with HTTP status code: 400")
29+
assertContains(smokeTestRunnerOutput, "#\tat aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsInterceptor.readBeforeDeserialization(SmokeTestsInterceptor.kt:19)")
30+
assertContains(smokeTestRunnerOutput, "#\tat aws.smithy.kotlin.runtime.http.interceptors.InterceptorExecutor.readBeforeDeserialization(InterceptorExecutor.kt:252)")
31+
}
32+
2333
@Test
2434
fun successServiceSkipTags() {
2535
val envVars = mapOf(SKIP_TAGS to "success")
@@ -39,14 +49,20 @@ class SmokeTestE2ETest {
3949
}
4050
}
4151

42-
private fun runSmokeTests(service: String, envVars: Map<String, String> = emptyMap()): String {
52+
private fun runSmokeTests(
53+
service: String,
54+
envVars: Map<String, String> = emptyMap(),
55+
expectingFailure: Boolean = false,
56+
): String {
4357
val sdkRootDir = System.getProperty("user.dir") + "/../../../"
44-
val runner = GradleRunner.create()
58+
59+
val task = GradleRunner.create()
4560
.withProjectDir(File(sdkRootDir))
4661
// FIXME: Remove `-Paws.kotlin.native=false` when Kotlin Native is ready
4762
.withArguments("-Paws.kotlin.native=false", ":tests:codegen:smoke-tests:services:$service:smokeTest")
4863
.withEnvironment(envVars)
49-
.build()
5064

51-
return runner.output
65+
val buildResult = if (expectingFailure) task.buildAndFail() else task.build()
66+
67+
return buildResult.output
5268
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
$version: "2"
2+
namespace smithy.kotlin.traits
3+
4+
use aws.protocols#awsJson1_0
5+
use aws.api#service
6+
use smithy.test#smokeTests
7+
use smithy.rules#endpointRuleSet
8+
9+
@trait(selector: "service")
10+
structure failedResponseTrait { }
11+
12+
@failedResponseTrait
13+
@awsJson1_0
14+
@service(sdkId: "Exception")
15+
@endpointRuleSet(
16+
version: "1.0",
17+
parameters: {},
18+
rules: [
19+
{
20+
"type": "endpoint",
21+
"conditions": [],
22+
"endpoint": {
23+
"url": "https://static.endpoint"
24+
}
25+
}
26+
]
27+
)
28+
service ExceptionService {
29+
version: "1.0.0",
30+
operations: [ TestOperation ],
31+
}
32+
33+
@smokeTests(
34+
[
35+
{
36+
id: "ExceptionTest"
37+
expect: {
38+
success: {}
39+
}
40+
}
41+
]
42+
)
43+
operation TestOperation {
44+
input := {
45+
bar: String
46+
}
47+
errors: [
48+
InvalidMessageError
49+
]
50+
}
51+
52+
@error("client")
53+
structure InvalidMessageError {}

0 commit comments

Comments
 (0)