Skip to content

Commit

Permalink
Scala 3 support for main modules (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
bplommer authored Aug 25, 2021
1 parent 4927244 commit f25b374
Show file tree
Hide file tree
Showing 73 changed files with 412 additions and 423 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ version = 2.7.5
style = defaultWithAlign
maxColumn = 120
rewrite.rules = [RedundantBraces,RedundantParens,PreferCurlyFors]
danglingParentheses = true
danglingParentheses.preset = true
14 changes: 7 additions & 7 deletions broker-integration-tests/consumer/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import com.itv.scalapact.plugin._

name := "consumer"

scalaVersion := "2.13.3"
scalaVersion := "2.13.6"

enablePlugins(ScalaPactPlugin)

lazy val pactVersionFile: SettingKey[File] = settingKey[File]("location of scala-pact version for examples")
pactVersionFile := baseDirectory.value.getParentFile.getParentFile / "version.sbt"

libraryDependencies ++= {
//A hack so we don't have to manually update the scala-pact version for the examples
lazy val pactVersion = IO.read(pactVersionFile.value).split('"')(1)
Seq(
"com.itv" %% "scalapact-scalatest-suite" % pactVersion % "test",
"org.scalatest" %% "scalatest" % "3.0.8" % "test"
)
//A hack so we don't have to manually update the scala-pact version for the examples
lazy val pactVersion = IO.read(pactVersionFile.value).split('"')(1)
Seq(
"com.itv" %% "scalapact-scalatest-suite" % pactVersion % "test",
"org.scalatest" %% "scalatest" % "3.2.9" % "test"
)
}

scalaPactEnv := ScalaPactEnv.defaults.withPort(8080)
2 changes: 1 addition & 1 deletion broker-integration-tests/consumer/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.3.2
sbt.version = 1.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package consumer
import java.io.File

import com.itv.scalapact.PactForgerSuite
import org.scalatest.{FunSpecLike, Matchers}
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.matchers.should.Matchers

import scala.io.{BufferedSource, Source}

class ProviderClientSpec extends PactForgerSuite with FunSpecLike with Matchers {
class ProviderClientSpec extends PactForgerSuite with AnyFunSpecLike with Matchers {

val CONSUMER = "scala-pact-integration-test-consumer"
val PROVIDER = "scala-pact-integration-test-provider"
Expand Down
22 changes: 11 additions & 11 deletions broker-integration-tests/provider/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import java.io.File

name := "provider"

scalaVersion := "2.13.3"
scalaVersion := "2.13.6"

enablePlugins(ScalaPactPlugin)

lazy val pactVersionFile: SettingKey[File] = settingKey[File]("location of scala-pact version for these tests")
pactVersionFile := baseDirectory.value.getParentFile.getParentFile / "version.sbt"

libraryDependencies ++= {
//A hack so we don't have to manually update the scala-pact version for the examples
lazy val pactVersion = IO.read(pactVersionFile.value).split('"')(1)
Seq(
"org.http4s" %% "http4s-blaze-server" % "0.21.7",
"org.http4s" %% "http4s-dsl" % "0.21.7",
"org.http4s" %% "http4s-circe" % "0.21.7",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"org.scalatest" %% "scalatest" % "3.0.8" % "test",
//A hack so we don't have to manually update the scala-pact version for the examples
lazy val pactVersion = IO.read(pactVersionFile.value).split('"')(1)
Seq(
"org.http4s" %% "http4s-blaze-server" % "0.23.1",
"org.http4s" %% "http4s-dsl" % "0.23.1",
"org.http4s" %% "http4s-circe" % "0.23.1",
"org.slf4j" % "slf4j-simple" % "1.6.4",
"org.scalatest" %% "scalatest" % "3.2.9" % "test",
"com.itv" %% "scalapact-scalatest-suite" % pactVersion % "test",
"org.scalaj" %% "scalaj-http" % "2.4.2" % "test",
"io.circe" %% "circe-parser" % "0.13.0"
"org.scalaj" %% "scalaj-http" % "2.4.2" % "test",
"io.circe" %% "circe-parser" % "0.14.1"
)
}
2 changes: 1 addition & 1 deletion broker-integration-tests/provider/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.3.2
sbt.version = 1.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import org.http4s._
import org.http4s.dsl.io._
import org.http4s.implicits._
import org.http4s.circe._
import org.http4s.util.CaseInsensitiveString
import io.circe.{Json, parser}
import org.typelevel.ci._

import scala.io.Source

Expand All @@ -22,15 +22,15 @@ object Provider {
}.orNotFound

def makeResponse(request: Request[IO]): IO[Response[IO]] = {
val pactHeader = request.headers.get(CaseInsensitiveString("Pact")).map(_.value).getOrElse("")
val pactHeader = request.headers.get(ci"Pact").map(_.head.value).getOrElse("")

val body = {
val source = Source.fromFile(new File("../consumer/master-expected.json"))
val b = source.getLines().mkString
source.close()
parser.parse(b).getOrElse(Json.obj())
}
Ok(body).map(_.putHeaders(Header("Pact", pactHeader)))
Ok(body).map(_.putHeaders(Header.Raw(ci"Pact", pactHeader)))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import java.util.concurrent.Executors

import cats.effect.IO
import cats.effect._
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.blaze.server.BlazeServerBuilder
import org.http4s.server._

import scala.concurrent.ExecutionContext

object AlternateStartupApproach extends IOApp {
override val executionContext = ExecutionContext.fromExecutor(
Executors.newFixedThreadPool(Runtime.getRuntime.availableProcessors())
)

// On ordinary start up, this service will begin here.
def run(args: List[String]): IO[ExitCode] =
serverResource
.use(_ => IO.never).as(ExitCode.Success)
.use(_ => IO.never)
.as(ExitCode.Success)

def serverResource: Resource[IO, Server[IO]] =
BlazeServerBuilder[IO](executionContext)
.bindHttp(8080)
.withHttpApp(Provider.service)
.resource
def serverResource: Resource[IO, Server] =
Resource.eval(Sync[IO].executionContext).flatMap { ec =>
BlazeServerBuilder[IO](ec)
.bindHttp(8080)
.withHttpApp(Provider.service)
.resource
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package provider

import org.scalatest.{BeforeAndAfterAll, FunSpec, Matchers}
import cats.effect.unsafe.implicits.global
import org.scalatest.BeforeAndAfterAll
import org.scalatest.matchers.should.Matchers
import org.scalatest.funspec.AnyFunSpec
import com.itv.scalapact.PactVerifySuite
import com.itv.scalapact.shared.{BrokerPublishData, ConsumerVersionSelector, PactBrokerAuthorization, PendingPactSettings}
import scalaj.http._

import scala.concurrent.duration._

class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll with PactVerifySuite {
class VerifyContractsSpec extends AnyFunSpec with Matchers with BeforeAndAfterAll with PactVerifySuite {
val serverAllocated =
AlternateStartupApproach.serverResource.allocated.unsafeRunSync()

Expand Down
Loading

0 comments on commit f25b374

Please sign in to comment.