Skip to content

Commit 84c3ee0

Browse files
committed
Add file-based test
1 parent 8f9a10d commit 84c3ee0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

core/src/test/scalajvm/sttp/client4/testing/HttpTestExtensions.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,25 @@ trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] =>
234234
new String(decompressedBytes) shouldBe "I'm not compressed"
235235
}
236236
}
237+
238+
"should compress a file-based request body using gzip" in {
239+
val testFileContent = "test file content"
240+
withTemporaryFile(Some(testFileContent.getBytes())) { file =>
241+
val req = basicRequest
242+
.compressBody(Encodings.Gzip)
243+
.response(asByteArrayAlways)
244+
.post(uri"$endpoint/echo/exact")
245+
.body(file)
246+
req.send(backend).toFuture().map { resp =>
247+
resp.code shouldBe StatusCode.Ok
248+
249+
val gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(resp.body))
250+
val decompressedBytes = gzipInputStream.readAllBytes()
251+
252+
new String(decompressedBytes) shouldBe testFileContent
253+
}
254+
}
255+
}
237256
}
238257

239258
private def withTemporaryFile[T](content: Option[Array[Byte]])(f: File => Future[T]): Future[T] = {

0 commit comments

Comments
 (0)