aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
diff options
context:
space:
mode:
authorSam Guymer <sam@guymer.me>2018-05-17 20:11:22 +1000
committerSam Guymer <sam@guymer.me>2018-05-19 00:37:52 +1000
commit92e10991df0d168d1972d4618fcc7e02e2e0a0fa (patch)
tree14e0d112fd47856a8c87ad1782d51a928b01bbf6 /core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
parent588395d018c258eb74f60ad95bad706698bdf915 (diff)
downloadsttp-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 'core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala')
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala65
1 files changed, 65 insertions, 0 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
new file mode 100644
index 0000000..aa0af07
--- /dev/null
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/streaming/StreamingTest.scala
@@ -0,0 +1,65 @@
+package com.softwaremill.sttp.testing.streaming
+
+import com.softwaremill.sttp._
+import com.softwaremill.sttp.testing.ForceWrapped
+import org.scalatest.{AsyncFreeSpec, BeforeAndAfterAll, Matchers}
+
+import scala.language.higherKinds
+
+trait StreamingTest[R[_], S] extends AsyncFreeSpec with Matchers with BeforeAndAfterAll with ForceWrapped {
+
+ private val endpoint = "localhost:51823"
+ private val body = "streaming test"
+
+ val testStreamingBackend: TestStreamingBackend[R, S]
+ import testStreamingBackend._
+
+ "stream request body" in {
+ sttp
+ .post(uri"$endpoint/streaming/echo")
+ .streamBody(bodyProducer(body))
+ .send()
+ .toFuture()
+ .map { response =>
+ response.unsafeBody shouldBe body
+ }
+ }
+
+ "receive a stream" in {
+ sttp
+ .post(uri"$endpoint/streaming/echo")
+ .body(body)
+ .response(asStream[S])
+ .send()
+ .toFuture()
+ .flatMap { response =>
+ bodyConsumer(response.unsafeBody).toFuture()
+ }
+ .map { responseBody =>
+ responseBody shouldBe body
+ }
+ }
+
+ "receive a stream from an https site" in {
+ sttp
+ // of course, you should never rely on the internet being available
+ // in tests, but that's so much easier than setting up an https
+ // testing server
+ .get(uri"https://softwaremill.com")
+ .response(asStream[S])
+ .send()
+ .toFuture()
+ .flatMap { response =>
+ bodyConsumer(response.unsafeBody).toFuture()
+ }
+ .map { responseBody =>
+ responseBody should include("</div>")
+ }
+ }
+
+ override protected def afterAll(): Unit = {
+ testStreamingBackend.backend.close()
+ super.afterAll()
+ }
+
+}