Skip to content

Commit 1745ded

Browse files
committed
Only test on jvm
1 parent 1e65bda commit 1745ded

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

core/src/test/scala/sttp/client4/testing/HttpTest.scala

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import java.io.{ByteArrayInputStream, UnsupportedEncodingException}
1414
import java.nio.ByteBuffer
1515
import scala.concurrent.Future
1616
import scala.concurrent.duration._
17-
import sttp.model.Encodings
18-
import java.util.zip.GZIPInputStream
19-
import java.util.zip.InflaterInputStream
2017

2118
trait HttpTest[F[_]]
2219
extends AsyncFreeSpec
@@ -467,38 +464,6 @@ trait HttpTest[F[_]]
467464
}
468465
}
469466
}
470-
471-
"should compress request body using gzip" in {
472-
val req = basicRequest
473-
.compressBody(Encodings.Gzip)
474-
.response(asByteArrayAlways)
475-
.post(uri"$endpoint/echo/exact")
476-
.body("I'm not compressed")
477-
req.send(backend).toFuture().map { resp =>
478-
resp.code shouldBe StatusCode.Ok
479-
480-
val gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(resp.body))
481-
val decompressedBytes = gzipInputStream.readAllBytes()
482-
483-
new String(decompressedBytes) shouldBe "I'm not compressed"
484-
}
485-
}
486-
487-
"should compress request body using deflate" in {
488-
val req = basicRequest
489-
.compressBody(Encodings.Deflate)
490-
.response(asByteArrayAlways)
491-
.post(uri"$endpoint/echo/exact")
492-
.body("I'm not compressed")
493-
req.send(backend).toFuture().map { resp =>
494-
resp.code shouldBe StatusCode.Ok
495-
496-
val inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(resp.body))
497-
val decompressedBytes = inflaterInputStream.readAllBytes()
498-
499-
new String(decompressedBytes) shouldBe "I'm not compressed"
500-
}
501-
}
502467
}
503468

504469
// in JavaScript the only way to set the content type is to use a Blob which defaults the filename to 'blob'

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import HttpTest.endpoint
1212
import org.scalatest.freespec.AsyncFreeSpecLike
1313
import sttp.client4.wrappers.{DigestAuthenticationBackend, FollowRedirectsBackend, TooManyRedirectsException}
1414
import sttp.model.headers.CookieWithMeta
15+
import sttp.model.Encodings
16+
import java.util.zip.GZIPInputStream
17+
import java.io.ByteArrayInputStream
18+
import java.util.zip.InflaterInputStream
1519

1620
trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] =>
1721
protected def supportsResponseAsInputStream = true
@@ -198,6 +202,40 @@ trait HttpTestExtensions[F[_]] extends AsyncFreeSpecLike { self: HttpTest[F] =>
198202
}
199203
}
200204

205+
"compression" - {
206+
"should compress request body using gzip" in {
207+
val req = basicRequest
208+
.compressBody(Encodings.Gzip)
209+
.response(asByteArrayAlways)
210+
.post(uri"$endpoint/echo/exact")
211+
.body("I'm not compressed")
212+
req.send(backend).toFuture().map { resp =>
213+
resp.code shouldBe StatusCode.Ok
214+
215+
val gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(resp.body))
216+
val decompressedBytes = gzipInputStream.readAllBytes()
217+
218+
new String(decompressedBytes) shouldBe "I'm not compressed"
219+
}
220+
}
221+
222+
"should compress request body using deflate" in {
223+
val req = basicRequest
224+
.compressBody(Encodings.Deflate)
225+
.response(asByteArrayAlways)
226+
.post(uri"$endpoint/echo/exact")
227+
.body("I'm not compressed")
228+
req.send(backend).toFuture().map { resp =>
229+
resp.code shouldBe StatusCode.Ok
230+
231+
val inflaterInputStream = new InflaterInputStream(new ByteArrayInputStream(resp.body))
232+
val decompressedBytes = inflaterInputStream.readAllBytes()
233+
234+
new String(decompressedBytes) shouldBe "I'm not compressed"
235+
}
236+
}
237+
}
238+
201239
private def withTemporaryFile[T](content: Option[Array[Byte]])(f: File => Future[T]): Future[T] = {
202240
val file = Files.createTempFile("sttp", "sttp")
203241
val result = Future {

0 commit comments

Comments
 (0)