@@ -7,12 +7,12 @@ package aws.smithy.kotlin.runtime.smithy.test
77import aws.smithy.kotlin.runtime.http.Headers
88import aws.smithy.kotlin.runtime.http.HttpBody
99import aws.smithy.kotlin.runtime.http.HttpStatusCode
10- import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
1110import aws.smithy.kotlin.runtime.http.engine.HttpClientEngine
1211import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineBase
1312import aws.smithy.kotlin.runtime.http.request.HttpRequest
1413import aws.smithy.kotlin.runtime.http.response.HttpCall
1514import aws.smithy.kotlin.runtime.http.response.HttpResponse
15+ import aws.smithy.kotlin.runtime.io.SdkByteReadChannel
1616import aws.smithy.kotlin.runtime.testing.runSuspendTest
1717import 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