From 421eb3d021b93d90f91d5e755cd07d9ae4034e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ja=C5=BCd=C5=BCewski?= Date: Wed, 29 Jun 2016 13:50:58 +0200 Subject: [PATCH] =htp simple head test to cheack manual completion with empty Source (#20853) * simple head test to cheack manual completion with empty Source, for issue 20182 --- .../directives/MethodDirectivesSpec.scala | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala index f60347e77d..3e83601175 100644 --- a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala @@ -4,8 +4,12 @@ package akka.http.scaladsl.server.directives -import akka.http.scaladsl.model.{ StatusCodes, HttpMethods } +import akka.http.scaladsl.model.{ ContentTypes, HttpEntity, StatusCodes, HttpMethods } import akka.http.scaladsl.server._ +import akka.stream.scaladsl.Source + +import scala.concurrent.Await +import scala.concurrent.duration.Duration class MethodDirectivesSpec extends RoutingSpec { @@ -23,6 +27,26 @@ class MethodDirectivesSpec extends RoutingSpec { } } + "head" should { + val headRoute = head { + complete(HttpEntity.Default( + ContentTypes.`application/octet-stream`, + 12345L, + Source.empty + )) + } + + "allow manual complete" in { + Head() ~> headRoute ~> check { + status shouldEqual StatusCodes.OK + + val lengthF = response._3.dataBytes.runFold(0)((c, _) => c+1) + val length = Await.result(lengthF, Duration(100, "millis")) + length shouldEqual 0 + } + } + } + "two failed `get` directives" should { "only result in a single Rejection" in { Put() ~> {