Skip to content

Commit f949a4b

Browse files
authored
fix(rt): emulate a real response body more closely to help catch subtle codegen bugs (#505)
1 parent 5997e2b commit f949a4b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

runtime/smithy-test/common/src/aws/smithy/kotlin/runtime/smithy/test/HttpResponseTest.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package aws.smithy.kotlin.runtime.smithy.test
77
import aws.smithy.kotlin.runtime.http.Headers
88
import aws.smithy.kotlin.runtime.http.HttpBody
99
import aws.smithy.kotlin.runtime.http.HttpStatusCode
10-
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
1110
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngine
1211
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineBase
1312
import aws.smithy.kotlin.runtime.http.request.HttpRequest
1413
import aws.smithy.kotlin.runtime.http.response.HttpCall
1514
import aws.smithy.kotlin.runtime.http.response.HttpResponse
15+
import aws.smithy.kotlin.runtime.io.SdkByteReadChannel
1616
import aws.smithy.kotlin.runtime.testing.runSuspendTest
1717
import aws.smithy.kotlin.runtime.time.Instant
1818

@@ -88,7 +88,16 @@ fun <T> httpResponseTest(block: HttpResponseTestBuilder<T>.() -> Unit) = runSusp
8888
}
8989

9090
val body: HttpBody = testBuilder.expected.body?.let {
91-
ByteArrayContent(it.encodeToByteArray())
91+
// emulate a real response stream which typically can only be consumed once
92+
// see: https://github.com/awslabs/aws-sdk-kotlin/issues/356
93+
object : HttpBody.Streaming() {
94+
private var consumed = false
95+
override fun readFrom(): SdkByteReadChannel {
96+
val content = if (consumed) ByteArray(0) else it.encodeToByteArray()
97+
consumed = true
98+
return SdkByteReadChannel(content)
99+
}
100+
}
92101
} ?: HttpBody.Empty
93102

94103
val resp = HttpResponse(testBuilder.expected.statusCode, headers, body)

0 commit comments

Comments
 (0)