From 280fbad03745ee622edb88966a1eecf8e88878b2 Mon Sep 17 00:00:00 2001 From: Simon Popugaev Date: Tue, 18 May 2021 13:35:13 +0300 Subject: [PATCH] Update BuildHelper.scala --- build.sbt | 10 ++++--- project/BuildHelper.scala | 2 +- .../akka/http/expose/ExposedRouteTest.scala | 8 +++++- .../akkahttp/DefaultAkkaRunnableSpec.scala | 27 ++++++++++++++++--- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index 4e787f2..cba6fef 100644 --- a/build.sbt +++ b/build.sbt @@ -36,13 +36,15 @@ lazy val zioTestAkkaHttp = .settings(stdSettings) .settings( libraryDependencies ++= Seq( - "dev.zio" %% "zio" % zioVersion, - "dev.zio" %% "zio-test" % zioVersion, - "dev.zio" %% "zio-test-sbt" % zioVersion % Test, + "dev.zio" %% "zio" % zioVersion, + "dev.zio" %% "zio-test" % zioVersion, + "dev.zio" %% "zio-test-sbt" % zioVersion % Test, + ), + libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-http" % akkaHttpVersion, "com.typesafe.akka" %% "akka-stream" % akkaVersion, "com.typesafe.akka" %% "akka-actor" % akkaVersion, "com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test, - ), + ).map(_.cross(CrossVersion.for3Use2_13)), testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")), ) diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 4e7a0ae..e3040ff 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -72,7 +72,7 @@ object BuildHelper { val stdSettings = Seq( scalacOptions := stdOptions, - crossScalaVersions := Seq("2.13.6", "2.12.15"), + crossScalaVersions := Seq("2.13.6", "2.12.15", "3.0.0"), ThisBuild / scalaVersion := crossScalaVersions.value.head, scalacOptions := stdOptions ++ extraOptions(scalaVersion.value), Test / parallelExecution := true, diff --git a/src/main/scala/akka/http/expose/ExposedRouteTest.scala b/src/main/scala/akka/http/expose/ExposedRouteTest.scala index 2e78ed1..0f2163c 100644 --- a/src/main/scala/akka/http/expose/ExposedRouteTest.scala +++ b/src/main/scala/akka/http/expose/ExposedRouteTest.scala @@ -22,7 +22,13 @@ trait ExposedRouteTest { */ def expectWebSocketUpgradeWithProtocol(assertion: Assertion[String]): Assertion[RouteTestResult.Completed] = (isWebSocketUpgrade && header[`Sec-WebSocket-Protocol`]( - isSome(hasField("protocols", _.protocols, hasSize[String](equalTo(1)) && hasFirst(assertion))), + isSome( + hasField( + "protocols", + (_: `Sec-WebSocket-Protocol`).protocols, + hasSize[String](equalTo(1)) && hasFirst(assertion), + ), + ), )) ?? "expectWebSocketUpgradeWithProtocol" protected def executeRequest( diff --git a/src/main/scala/zio/test/akkahttp/DefaultAkkaRunnableSpec.scala b/src/main/scala/zio/test/akkahttp/DefaultAkkaRunnableSpec.scala index 700dd0a..61db85c 100644 --- a/src/main/scala/zio/test/akkahttp/DefaultAkkaRunnableSpec.scala +++ b/src/main/scala/zio/test/akkahttp/DefaultAkkaRunnableSpec.scala @@ -1,8 +1,17 @@ package zio.test.akkahttp +import akka.actor.ActorSystem +import akka.stream.Materializer +import zio.blocking.Blocking +import zio.clock.Clock +import zio.console.Console +import zio._ import zio.duration._ -import zio.test.environment.{testEnvironment, TestEnvironment} -import zio.test.{RunnableSpec, TestAspect, TestExecutor, TestRunner} +import zio.random.Random +import zio.system.System +import zio.test.akkahttp.RouteTest.Config +import zio.test.environment.{testEnvironment, Live, TestClock, TestConsole, TestEnvironment, TestRandom, TestSystem} +import zio.test.{Annotations, RunnableSpec, Sized, TestAspect, TestConfig, TestExecutor, TestRunner} trait DefaultAkkaRunnableSpec extends RunnableSpec[RouteTestEnvironment.TestEnvironment with TestEnvironment, Any] @@ -11,7 +20,17 @@ trait DefaultAkkaRunnableSpec : List[TestAspect[Nothing, RouteTestEnvironment.TestEnvironment with TestEnvironment, Nothing, Any]] = List(TestAspect.timeoutWarning(60.seconds)) - override def runner: TestRunner[RouteTestEnvironment.TestEnvironment with TestEnvironment, Any] = - TestRunner(TestExecutor.default(RouteTestEnvironment.environment ++ testEnvironment)) + override def runner: TestRunner[RouteTestEnvironment.TestEnvironment with TestEnvironment, Any] = { + // TODO: remove workaround once izumi macros are ported to Scala 3.x + val akkaEnv: ULayer[Has[ActorSystem] with Has[Materializer] with Has[Config]] = RouteTestEnvironment.environment + val zEnv: ULayer[ + Has[Annotations.Service] with Has[Live.Service] with Has[Sized.Service] with Has[TestClock.Service] with Has[ + TestConfig.Service, + ] with Has[TestConsole.Service] with Has[TestRandom.Service] with Has[TestSystem.Service] with Has[ + Clock.Service, + ] with Has[Console.Service] with Has[System.Service] with Has[Random.Service] with Has[Blocking.Service], + ] = testEnvironment + TestRunner(TestExecutor.default(akkaEnv ++ zEnv)) + } }