Skip to content

Commit a6307fd

Browse files
committed
Add tapir routes test
1 parent 4fe34ff commit a6307fd

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

instrumentation/pekko/pekko-http-1.0/javaagent/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
library("org.apache.pekko:pekko-http_2.12:1.0.0")
3232
library("org.apache.pekko:pekko-stream_2.12:1.0.1")
3333

34+
testImplementation("com.softwaremill.sttp.tapir:tapir-pekko-http-server_2.12:1.7.0")
35+
3436
testInstrumentation(project(":instrumentation:pekko:pekko-actor-1.0:javaagent"))
3537
testInstrumentation(project(":instrumentation:executors:javaagent"))
3638

instrumentation/pekko/pekko-http-1.0/javaagent/src/test/scala/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/PekkoHttpServerRouteTest.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import org.junit.jupiter.api.{AfterAll, Test, TestInstance}
3131

3232
import java.net.{URI, URISyntaxException}
3333
import java.util.function.Consumer
34-
import scala.concurrent.Await
34+
import scala.concurrent.{Await, ExecutionContext, Future}
3535
import scala.concurrent.duration.DurationInt
36+
import sttp.tapir._
37+
import sttp.tapir.server.pekkohttp.PekkoHttpServerInterpreter
3638

3739
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3840
class PekkoHttpServerRouteTest {
@@ -77,6 +79,25 @@ class PekkoHttpServerRouteTest {
7779
test(route, "/test/1", "GET /test/*")
7880
}
7981

82+
@Test def testTapirRoutes(): Unit = {
83+
def makeRoute(input: EndpointInput[Unit]) =
84+
endpoint.get
85+
.in(input)
86+
.errorOut(stringBody)
87+
.out(stringBody)
88+
.serverLogicPure[Future](_ => Right("ok"))
89+
90+
val interpreter = PekkoHttpServerInterpreter()(system.dispatcher)
91+
val route1 = interpreter.toRoute(makeRoute("test" / "1"))
92+
val route2 = interpreter.toRoute(makeRoute("test" / "2"))
93+
val route3 = interpreter.toRoute(makeRoute("test" / "3"))
94+
val route4 = interpreter.toRoute(makeRoute("test" / "4"))
95+
96+
val routes = concat(route1, route2, route3, route4)
97+
98+
test(routes, "/test/3", "GET")
99+
}
100+
80101
def test(route: Route, path: String, spanName: String): Unit = {
81102
val port = PortUtils.findOpenPort
82103
val address: URI = buildAddress(port)

0 commit comments

Comments
 (0)