forked from softwaremill/tapir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
softwaremill#1400: fix play server interpreter when routes are put in…
… context (cherry picked from commit 343995a)
- Loading branch information
Showing
3 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
server/play-server/src/test/scala/sttp/tapir/server/play/PlayServerWithContextTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sttp.tapir.server.play | ||
|
||
import akka.actor.ActorSystem | ||
import cats.effect.IO | ||
import org.scalatest.matchers.should.Matchers._ | ||
import play.api.Mode | ||
import play.api.routing.Router | ||
import play.core.server.{DefaultAkkaHttpServerComponents, ServerConfig} | ||
import sttp.client3._ | ||
import sttp.tapir._ | ||
import sttp.tapir.tests.Test | ||
|
||
import scala.concurrent.Future | ||
|
||
class PlayServerWithContextTest(backend: SttpBackend[IO, Any])(implicit _actorSystem: ActorSystem) { | ||
import _actorSystem.dispatcher | ||
|
||
def tests(): List[Test] = List( | ||
Test("server with play.http.context set") { | ||
val e = endpoint.get.in("hello").out(stringBody).serverLogic[Future](_ => Future.successful(Right("world"))) | ||
val components = new DefaultAkkaHttpServerComponents { | ||
override lazy val serverConfig: ServerConfig = ServerConfig(port = Some(0), address = "127.0.0.1", mode = Mode.Test) | ||
override lazy val actorSystem: ActorSystem = ActorSystem("tapir", defaultExecutionContext = Some(_actorSystem.dispatcher)) | ||
override def router: Router = Router.from(PlayServerInterpreter().toRoutes(e)).withPrefix("/test") | ||
} | ||
val s = components.server | ||
val r = Future.successful(()).flatMap { _ => | ||
basicRequest | ||
.get(uri"http://localhost:${s.mainAddress.getPort}/test/hello") | ||
.send(backend) | ||
.map(_.body shouldBe Right("world")) | ||
.unsafeToFuture() | ||
} | ||
r.onComplete(_ => s.stop()) | ||
r | ||
} | ||
) | ||
} |