11package kamon .akka .http
22
33import akka .actor .ActorSystem
4- import akka .http .scaladsl .model .{HttpEntity , HttpRequest , HttpResponse , StatusCodes }
4+ import akka .http .scaladsl .model .{ContentTypes , HttpEntity , HttpRequest , HttpResponse , StatusCodes }
55import akka .stream .ActorMaterializer
66import akka .stream .scaladsl .{Flow , Sink , Source }
7+ import akka .util .ByteString
78import kamon .instrumentation .akka .http .ServerFlowWrapper
89import kamon .testkit .InitAndStopKamonAfterAll
910import org .scalatest .concurrent .ScalaFutures
@@ -20,6 +21,13 @@ class ServerFlowWrapperSpec extends AnyWordSpecLike with Matchers with ScalaFutu
2021 HttpResponse (status = StatusCodes .OK , entity = HttpEntity (" OK" ))
2122 }
2223
24+ private val defaultReturningFlow = Flow [HttpRequest ].map { _ =>
25+ HttpResponse (status = StatusCodes .OK , entity = HttpEntity .Default (
26+ ContentTypes .`text/plain(UTF-8)`,
27+ 2 ,
28+ Source .single(ByteString .apply(" OK" ))))
29+ }
30+
2331 " the server flow wrapper" should {
2432 " keep strict entities strict" in {
2533 val flow = ServerFlowWrapper (okReturningFlow, " localhost" , 8080 )
@@ -28,9 +36,23 @@ class ServerFlowWrapperSpec extends AnyWordSpecLike with Matchers with ScalaFutu
2836 .via(flow)
2937 .runWith(Sink .head)
3038 .futureValue
39+
3140 response.entity should matchPattern {
3241 case HttpEntity .Strict (_, _) =>
3342 }
3443 }
44+
45+ " keep default entities default" in {
46+ val flow = ServerFlowWrapper (defaultReturningFlow, " localhost" , 8081 )
47+ val request = HttpRequest ()
48+ val response = Source .single(request)
49+ .via(flow)
50+ .runWith(Sink .head)
51+ .futureValue
52+
53+ response.entity should matchPattern {
54+ case _ : HttpEntity .Default =>
55+ }
56+ }
3557 }
3658}
0 commit comments