Skip to content

Commit

Permalink
Enable cross-compilation for Scala 2.13 and Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
scoquelin committed Jul 27, 2024
1 parent 06010f8 commit ae43c0f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
run: sbt "unitTests / test"
- name: Run integration tests
run: sbt "integrationTests / test"
- name: Run all tests using Scala 3
run: sbt ";++3.3.3;testAll"
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.13.14"
ThisBuild / crossScalaVersions := Seq("2.13.14", "3.3.3")

lazy val root = (project in file("."))
.settings(
Expand Down Expand Up @@ -42,7 +43,7 @@ lazy val integrationTests = (project in file ("modules/tests/it"))
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"com.dimafeng" %% "testcontainers-scala" % "0.41.4" % Test,
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.41.4" % Test,
"ch.qos.logback" % "logback-classic" % "1.5.6" % Test
"ch.qos.logback" % "logback-classic" % "1.5.6" % Test,
)
)
.dependsOn(api, core)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.github.scoquelin.arugula

import com.github.scoquelin.arugula.api.commands.client.RedisCommandsClient
import com.dimafeng.testcontainers.scalatest.TestContainerForAll
import com.dimafeng.testcontainers.{DockerComposeContainer, ExposedService}
import com.github.scoquelin.arugula.BaseRedisCommandsIntegrationSpec._
import com.github.scoquelin.arugula.api.commands.client.RedisCommandsClient
import com.github.scoquelin.arugula.commands.client.LettuceRedisCommandsClient
import com.github.scoquelin.arugula.config.LettuceRedisClientConfig

import scala.jdk.FunctionConverters.enrichAsJavaFunction

import com.dimafeng.testcontainers.scalatest.TestContainerForAll
import com.dimafeng.testcontainers.{DockerComposeContainer, ExposedService}
import io.lettuce.core.internal.HostAndPort
import io.lettuce.core.resource.{ClientResources, DnsResolvers, MappingSocketAddressResolver}
import org.scalatest.BeforeAndAfterEach
import org.scalatest.wordspec.AsyncWordSpecLike
import org.scalatest.{BeforeAndAfterEach, Suite}
import org.testcontainers.containers.wait.strategy.Wait

import java.io.File
import scala.jdk.FunctionConverters.enrichAsJavaFunction

trait BaseRedisCommandsIntegrationSpec extends AsyncWordSpecLike with TestContainerForAll with BeforeAndAfterEach { self: Suite =>
trait BaseRedisCommandsIntegrationSpec extends AsyncWordSpecLike with TestContainerForAll with BeforeAndAfterEach {
var redisSingleNodeCommandsClient: RedisCommandsClient[String, String] = null
var redisClusterCommandsClient: RedisCommandsClient[String, String] = null

override val containerDef = {
override val containerDef: DockerComposeContainer.Def = {
DockerComposeContainer.Def(
composeFiles = new File("src/test/resources/docker-compose.yml"),
exposedServices = Seq(
Expand All @@ -31,13 +29,13 @@ trait BaseRedisCommandsIntegrationSpec extends AsyncWordSpecLike with TestContai
)
}

override def afterContainersStart(container: Containers): Unit = {
super.afterContainersStart(container)
override def afterContainersStart(containers: Containers): Unit = {
super.afterContainersStart(containers)

redisSingleNodeCommandsClient = LettuceRedisCommandsClient(
LettuceRedisClientConfig(
container.getServiceHost(RedisSingleNode, RedisSingleNodePort),
container.getServicePort(RedisSingleNode, RedisSingleNodePort)
host = containers.getServiceHost(RedisSingleNode, RedisSingleNodePort),
port = containers.getServicePort(RedisSingleNode, RedisSingleNodePort)
)
)

Expand All @@ -55,9 +53,9 @@ trait BaseRedisCommandsIntegrationSpec extends AsyncWordSpecLike with TestContai

redisClusterCommandsClient = LettuceRedisCommandsClient(
LettuceRedisClientConfig(
container.getServiceHost(RedisClusterNode, RedisClusterPort),
container.getServicePort(RedisClusterNode, RedisClusterPort),
clientResources
host = containers.getServiceHost(RedisClusterNode, RedisClusterPort),
port = containers.getServicePort(RedisClusterNode, RedisClusterPort),
clientResources = clientResources
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class RedisCommandsIntegrationSpec extends BaseRedisCommandsIntegrationSpec with
keyValue <- client.sendCommand(_.get(key))
_ <- keyValue match {
case Some(expectedValue) => expectedValue shouldBe value
case None => fail
case None => fail()
}
deleted <- client.sendCommand(_.del(key))
_ <- deleted shouldBe 1L
Expand All @@ -62,12 +62,12 @@ class RedisCommandsIntegrationSpec extends BaseRedisCommandsIntegrationSpec with
keyValue <- client.sendCommand(_.get(key))
_ <- keyValue match {
case Some(expectedValue) => expectedValue shouldBe value
case None => fail
case None => fail()
}
ttl <- client.sendCommand(_.ttl(key))
_ <- ttl match {
case Some(timeToLive) => assert(timeToLive > (expireIn - 1.minute) && timeToLive <= expireIn)
case None => fail
case None => fail()
}
deleted <- client.sendCommand(_.del(key))
_ <- deleted shouldBe 1L
Expand Down Expand Up @@ -194,7 +194,7 @@ class RedisCommandsIntegrationSpec extends BaseRedisCommandsIntegrationSpec with
fieldValue <- client.sendCommand(_.hGet(key, field))
_ <- fieldValue match {
case Some(expectedFieldValue) => expectedFieldValue shouldBe value
case None => fail
case None => fail()
}
deleted <- client.sendCommand(_.hDel(key, field))
_ <- deleted shouldBe 1L
Expand All @@ -221,7 +221,7 @@ class RedisCommandsIntegrationSpec extends BaseRedisCommandsIntegrationSpec with
fieldValue <- client.sendCommand(_.hGet(key, field))
_ <- fieldValue match {
case Some(expectedFieldValue) => expectedFieldValue.toInt shouldBe value
case None => fail
case None => fail()
}
deleted <- client.sendCommand(_.hDel(key, field))
_ <- deleted shouldBe 1L
Expand Down Expand Up @@ -250,14 +250,14 @@ class RedisCommandsIntegrationSpec extends BaseRedisCommandsIntegrationSpec with
)))
_ <- pipelineOutcome match {
case Some(operationsOutcome) => operationsOutcome shouldBe List(true, false, true)
case None => fail
case None => fail()
}
keyExists <- client.sendCommand(_.exists(key))
_ <- keyExists shouldBe true
ttl <- client.sendCommand(_.ttl(key))
_ <- ttl match {
case Some(timeToLive) => assert(timeToLive > (expireIn - 1.minute) && timeToLive <= expireIn)
case None => fail
case None => fail()
}
} yield succeed
}
Expand Down

0 comments on commit ae43c0f

Please sign in to comment.