diff options
author | Sam Guymer <sam@guymer.me> | 2018-05-17 20:11:22 +1000 |
---|---|---|
committer | Sam Guymer <sam@guymer.me> | 2018-05-19 00:37:52 +1000 |
commit | 92e10991df0d168d1972d4618fcc7e02e2e0a0fa (patch) | |
tree | 14e0d112fd47856a8c87ad1782d51a928b01bbf6 /async-http-client-backend | |
parent | 588395d018c258eb74f60ad95bad706698bdf915 (diff) | |
download | sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.gz sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.tar.bz2 sttp-92e10991df0d168d1972d4618fcc7e02e2e0a0fa.zip |
Move backend tests into their projects
Instead of having a single project which tests all backends, each
backend now implements a http test trait along with a streaming test
trait if it supports streaming. The test http server has been moved into
its own project and is started automatically before running a backends
test. This allows each backend to be tested without the possibility of
dependency eviction from another backend or the test http server. It
also has the side effect of parallelizing the tests providing a speed
up when run with multiple cores.
Diffstat (limited to 'async-http-client-backend')
7 files changed, 133 insertions, 0 deletions
diff --git a/async-http-client-backend/cats/src/test/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHttpTest.scala b/async-http-client-backend/cats/src/test/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHttpTest.scala new file mode 100644 index 0000000..5136914 --- /dev/null +++ b/async-http-client-backend/cats/src/test/scala/com/softwaremill/sttp/asynchttpclient/cats/AsyncHttpClientCatsHttpTest.scala @@ -0,0 +1,12 @@ +package com.softwaremill.sttp.asynchttpclient.cats + +import cats.effect.IO +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.impl.cats.convertCatsIOToFuture +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} + +class AsyncHttpClientCatsHttpTest extends HttpTest[IO] { + + override implicit val backend: SttpBackend[IO, Nothing] = AsyncHttpClientCatsBackend() + override implicit val convertToFuture: ConvertToFuture[IO] = convertCatsIOToFuture +} 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..565db5c --- /dev/null +++ b/async-http-client-backend/fs2/src/test/scala/com/softwaremill/sttp/asynchttpclient/fs2/AsyncHttpClientFs2HttpStreamingTest.scala @@ -0,0 +1,40 @@ +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, TestStreamingBackend} +import com.softwaremill.sttp.testing.ConvertToFuture +import fs2.{Chunk, Stream, text} +import scala.concurrent.Future + +class AsyncHttpClientFs2HttpStreamingTest extends StreamingTest[IO, Stream[IO, ByteBuffer]] { + + override val testStreamingBackend: TestStreamingBackend[IO, Stream[IO, ByteBuffer]] = + new AsyncHttpClientFs2TestStreamingBackend +} + +class AsyncHttpClientFs2TestStreamingBackend extends TestStreamingBackend[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() + } +} diff --git a/async-http-client-backend/future/src/test/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHttpTest.scala b/async-http-client-backend/future/src/test/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHttpTest.scala new file mode 100644 index 0000000..58d8aa8 --- /dev/null +++ b/async-http-client-backend/future/src/test/scala/com/softwaremill/sttp/asynchttpclient/future/AsyncHttpClientFutureHttpTest.scala @@ -0,0 +1,12 @@ +package com.softwaremill.sttp.asynchttpclient.future + +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} + +import scala.concurrent.Future + +class AsyncHttpClientFutureHttpTest extends HttpTest[Future] { + + override implicit val backend: SttpBackend[Future, Nothing] = AsyncHttpClientFutureBackend() + override implicit val convertToFuture: ConvertToFuture[Future] = ConvertToFuture.future +} diff --git a/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHttpTest.scala b/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHttpTest.scala new file mode 100644 index 0000000..a08e738 --- /dev/null +++ b/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixHttpTest.scala @@ -0,0 +1,15 @@ +package com.softwaremill.sttp.asynchttpclient.monix + +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.impl.monix.convertMonixTaskToFuture +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} +import monix.eval.Task + +class AsyncHttpClientMonixHttpTest extends HttpTest[Task] { + + import monix.execution.Scheduler.Implicits.global + + override implicit val backend: SttpBackend[Task, Nothing] = AsyncHttpClientMonixBackend() + override implicit val convertToFuture: ConvertToFuture[Task] = convertMonixTaskToFuture + +} diff --git a/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixStreamingTest.scala b/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixStreamingTest.scala new file mode 100644 index 0000000..34c15ff --- /dev/null +++ b/async-http-client-backend/monix/src/test/scala/com/softwaremill/sttp/asynchttpclient/monix/AsyncHttpClientMonixStreamingTest.scala @@ -0,0 +1,26 @@ +package com.softwaremill.sttp.asynchttpclient.monix + +import java.nio.ByteBuffer + +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.impl.monix.MonixTestStreamingBackend +import com.softwaremill.sttp.testing.streaming.{StreamingTest, TestStreamingBackend} +import monix.eval.Task +import monix.reactive.Observable + +class AsyncHttpClientMonixStreamingTest extends StreamingTest[Task, Observable[ByteBuffer]] { + + override val testStreamingBackend: TestStreamingBackend[Task, Observable[ByteBuffer]] = + new AsyncHttpClientMonixTestStreamingBackend +} + +class AsyncHttpClientMonixTestStreamingBackend extends MonixTestStreamingBackend[ByteBuffer] { + + import monix.execution.Scheduler.Implicits.global + + override def toByteArray(v: ByteBuffer): Array[Byte] = v.array() + override def fromByteArray(v: Array[Byte]): ByteBuffer = ByteBuffer.wrap(v) + + override implicit val backend: SttpBackend[Task, Observable[ByteBuffer]] = + AsyncHttpClientMonixBackend() +} diff --git a/async-http-client-backend/scalaz/src/test/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHttpTest.scala b/async-http-client-backend/scalaz/src/test/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHttpTest.scala new file mode 100644 index 0000000..67acc09 --- /dev/null +++ b/async-http-client-backend/scalaz/src/test/scala/com/softwaremill/sttp/asynchttpclient/scalaz/AsyncHttpClientScalazHttpTest.scala @@ -0,0 +1,13 @@ +package com.softwaremill.sttp.asynchttpclient.scalaz + +import com.softwaremill.sttp.SttpBackend +import com.softwaremill.sttp.impl.scalaz.convertScalazTaskToFuture +import com.softwaremill.sttp.testing.{ConvertToFuture, HttpTest} + +import scalaz.concurrent.Task + +class AsyncHttpClientScalazHttpTest extends HttpTest[Task] { + + override implicit val backend: SttpBackend[Task, Nothing] = AsyncHttpClientScalazBackend() + override implicit val convertToFuture: ConvertToFuture[Task] = convertScalazTaskToFuture +} |