diff options
Diffstat (limited to 'async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2')
2 files changed, 48 insertions, 0 deletions
diff --git a/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpStreamingTest.scala b/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpStreamingTest.scala new file mode 100644 index 0000000..56bb18b --- /dev/null +++ b/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpStreamingTest.scala @@ -0,0 +1,33 @@ +package com.softwaremill.sttp.asynchttpclient.fs2 + +import java.nio.ByteBuffer + +import cats.effect.IO +import cats.instances.string._ +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.testing.streaming.StreamingTest +import com.softwaremill.sttp.testing.ConvertToFuture +import fs2.{Chunk, Stream, text} +import scala.concurrent.Future + +class AsyncHttpClientFs2HttpStreamingTest extends StreamingTest[IO, Stream[IO, ByteBuffer]] { + + override implicit val backend: SttpBackend[IO, Stream[IO, ByteBuffer]] = AsyncHttpClientFs2Backend[IO]() + + override implicit val convertToFuture: ConvertToFuture[IO] = + new ConvertToFuture[IO] { + override def toFuture[T](value: IO[T]): Future[T] = + value.unsafeToFuture() + } + + override def bodyProducer(body: String): Stream[IO, ByteBuffer] = + Stream.emits(body.getBytes("utf-8")).map(b => ByteBuffer.wrap(Array(b))) + + override def bodyConsumer(stream: Stream[IO, ByteBuffer]): IO[String] = + stream + .map(bb => Chunk.array(bb.array)) + .through(text.utf8DecodeC) + .compile + .foldMonoid + +} diff --git a/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpTest.scala b/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpTest.scala new file mode 100644 index 0000000..7772c23 --- /dev/null +++ b/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpTest.scala @@ -0,0 +1,15 @@ +package com.softwaremill.sttp.asynchttpclient.fs2 + +import cats.effect.IO +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} + +import scala.concurrent.Future + +class AsyncHttpClientFs2HttpTest extends HttpTest[IO] { + + override implicit val backend: SttpBackend[IO, Nothing] = AsyncHttpClientFs2Backend() + override implicit val convertToFuture: ConvertToFuture[IO] = new ConvertToFuture[IO] { + override def toFuture[T](value: IO[T]): Future[T] = value.unsafeToFuture() + } +} |