Skip to content

Commit

Permalink
Merge pull request #45 from senia-psm/senia-psm-patch-1
Browse files Browse the repository at this point in the history
Scala 3 support
  • Loading branch information
senia-psm authored Sep 24, 2021
2 parents f336579 + 280fbad commit f40177c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
10 changes: 6 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
)
2 changes: 1 addition & 1 deletion project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/akka/http/expose/ExposedRouteTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
27 changes: 23 additions & 4 deletions src/main/scala/zio/test/akkahttp/DefaultAkkaRunnableSpec.scala
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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))
}

}

0 comments on commit f40177c

Please sign in to comment.