Skip to content

Commit

Permalink
run scalafmt and check on build
Browse files Browse the repository at this point in the history
  • Loading branch information
jbwheatley committed Oct 31, 2020
1 parent 85978df commit c4554a4
Show file tree
Hide file tree
Showing 86 changed files with 1,568 additions and 1,152 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.0.1
version = 2.7.5
style = defaultWithAlign
maxColumn = 120
rewrite.rules = [RedundantBraces,RedundantParens,PreferCurlyFors]
Expand Down
1 change: 1 addition & 0 deletions commands.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ addCommandAlias(
addCommandAlias(
"localPublishScalaPact",
List(
"scalafmtCheckAll",
"+clean",
"+update",
"+compile",
Expand Down
47 changes: 24 additions & 23 deletions pact-spec-tests/src/test/scala/pactspec/util/PactSpecLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object SpecReader {

case Left(s) =>
Left(s)
}
}

val jsonStringToResponseSpec: String => Either[String, ResponseSpec] = json =>
jsonStringToSpec[InteractionResponse](json)(PactImplicits.InteractionResponseDecodeJson) match {
Expand All @@ -94,7 +94,7 @@ object SpecReader {

case Left(s) =>
Left(s)
}
}

}

Expand All @@ -111,27 +111,28 @@ object JsonBodySpecialCaseHelper {
.leftMap(e => "Extracting 'comment': " + e)

def extractInteractionRequestOrResponse[I]
: String => String => argonaut.DecodeJson[I] => Either[String, (I, Option[String])] =
: String => String => argonaut.DecodeJson[I] => Either[String, (I, Option[String])] =
field =>
json => { implicit decoder =>
separateRequestResponseFromBody(field)(json).flatMap(RequestResponseAndBody.unapply) match {
case Some((Some(requestResponseMinusBody), maybeBody)) =>
requestResponseMinusBody.toString
.decodeEither[I]
.map(i => (i, maybeBody))
.leftMap(e => "Extracting 'expected or actual': " + e)

case Some((None, _)) =>
val msg = s"Could not convert request to Json object: $json"
PactLogger.error(msg)
Left(msg)

case None =>
val msg = s"Problem splitting request from body in: $json"
PactLogger.error(msg)
Left(msg)
}
}
json => {
implicit decoder =>
separateRequestResponseFromBody(field)(json).flatMap(RequestResponseAndBody.unapply) match {
case Some((Some(requestResponseMinusBody), maybeBody)) =>
requestResponseMinusBody.toString
.decodeEither[I]
.map(i => (i, maybeBody))
.leftMap(e => "Extracting 'expected or actual': " + e)

case Some((None, _)) =>
val msg = s"Could not convert request to Json object: $json"
PactLogger.error(msg)
Left(msg)

case None =>
val msg = s"Problem splitting request from body in: $json"
PactLogger.error(msg)
Left(msg)
}
}

private lazy val separateRequestResponseFromBody: String => String => Option[RequestResponseAndBody] = field =>
json =>
Expand All @@ -146,7 +147,7 @@ object JsonBodySpecialCaseHelper {
}

RequestResponseAndBody(minusBody, requestBody)
}
}

final case class RequestResponseAndBody(requestMinusBody: Option[Json], body: Option[String])

Expand Down
129 changes: 73 additions & 56 deletions pact-spec-tests/src/test/scala/pactspec/util/PactSpecTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ trait PactSpecTester extends FunSpec with Matchers {

protected val fetchRequestSpec: String => StrictTestMode => (RequestSpec, StrictTestMode, String) = path =>
testMode =>
(PactSpecLoader
.deserializeRequestSpec(PactSpecLoader.fromResource(pactSpecVersion, path))
.getOrElse(throw new Exception("Failed to deserialise request spec")),
testMode,
fileNameFromPath(path))
(
PactSpecLoader
.deserializeRequestSpec(PactSpecLoader.fromResource(pactSpecVersion, path))
.getOrElse(throw new Exception("Failed to deserialise request spec")),
testMode,
fileNameFromPath(path)
)

protected def testRequestSpecs(specFiles: List[(RequestSpec, StrictTestMode, String)]): Unit =
specFiles.foreach { specAndMode =>
Expand All @@ -40,45 +42,52 @@ trait PactSpecTester extends FunSpec with Matchers {

}

private def doRequestMatch(spec: RequestSpec,
i: Interaction,
strictMatching: Boolean,
shouldMatch: Boolean,
path: String): Unit =
private def doRequestMatch(
spec: RequestSpec,
i: Interaction,
strictMatching: Boolean,
shouldMatch: Boolean,
path: String
): Unit =
matchSingleRequest(strictMatching, i.request.matchingRules, i.request, spec.actual) match {
case MatchOutcomeSuccess =>

if (!shouldMatch)
fail(
makeErrorString(shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
"")
makeErrorString(
shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
""
)
)

case e: MatchOutcomeFailed =>
if (shouldMatch)
fail(
makeErrorString(shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
e.renderDifferences)
makeErrorString(
shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
e.renderDifferences
)
)
}

protected val fetchResponseSpec: String => StrictTestMode => (ResponseSpec, StrictTestMode, String) = path =>
testMode =>
(PactSpecLoader
.deserializeResponseSpec(PactSpecLoader.fromResource(pactSpecVersion, path))
.getOrElse(throw new Exception("Failed to deserialise response spec")),
testMode,
fileNameFromPath(path))
(
PactSpecLoader
.deserializeResponseSpec(PactSpecLoader.fromResource(pactSpecVersion, path))
.getOrElse(throw new Exception("Failed to deserialise response spec")),
testMode,
fileNameFromPath(path)
)

protected def testResponseSpecs(specFiles: List[(ResponseSpec, StrictTestMode, String)]): Unit =
specFiles.foreach { specAndMode =>
Expand All @@ -100,44 +109,52 @@ trait PactSpecTester extends FunSpec with Matchers {

}

private def doResponseMatch(spec: ResponseSpec,
i: Interaction,
strictMatching: Boolean,
shouldMatch: Boolean,
path: String): Unit =
private def doResponseMatch(
spec: ResponseSpec,
i: Interaction,
strictMatching: Boolean,
shouldMatch: Boolean,
path: String
): Unit =
matchSingleResponse(strictMatching, i.response.matchingRules, i.response, spec.actual) match {
case MatchOutcomeSuccess =>
if (!shouldMatch)
fail(
makeErrorString(shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
"")
makeErrorString(
shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
""
)
)

case e: MatchOutcomeFailed =>
if (shouldMatch)
fail(
makeErrorString(shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
e.renderDifferences)
makeErrorString(
shouldMatch,
path,
spec.comment,
strictMatching,
spec.actual.renderAsString,
spec.expected.renderAsString,
e.renderDifferences
)
)
}

private def makeErrorString(shouldMatch: Boolean,
path: String,
comment: String,
strictMatching: Boolean,
actual: String,
expected: String,
differences: String): String =
private def makeErrorString(
shouldMatch: Boolean,
path: String,
comment: String,
strictMatching: Boolean,
actual: String,
expected: String,
differences: String
): String =
s"Expected match: $shouldMatch\n[$path] " + comment + "\nStrict matching: '" + strictMatching + "'\n\nExpected:\n" + expected + "\nActual:\n" + actual + "\nMatch Errors: [\n" + differences + "\n]"

}
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.0.0")

addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.itv.scalapact.plugin
import com.itv.scalapact.http._
import com.itv.scalapact.json._
import com.itv.scalapact.plugin.shared._
import com.itv.scalapact.shared.{ConsumerVersionSelector, PactBrokerAuthorization, ProviderStateResult, ScalaPactSettings}
import com.itv.scalapact.shared._
import com.itv.scalapact.shared.ProviderStateResult.SetupProviderState
import sbt.Keys._
import sbt.plugins.JvmPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import com.itv.scalapact.shared.{BrokerPublishData, ScalaPactSettings}

import scala.concurrent.duration._

case class ScalaPactEnv(protocol: Option[String],
host: Option[String],
port: Option[Int],
localPactFilePath: Option[String],
strictMode: Option[Boolean],
clientTimeout: Option[Duration],
outputPath: Option[String],
publishResultsEnabled: Option[BrokerPublishData],
enablePending: Option[Boolean]
case class ScalaPactEnv(
protocol: Option[String],
host: Option[String],
port: Option[Int],
localPactFilePath: Option[String],
strictMode: Option[Boolean],
clientTimeout: Option[Duration],
outputPath: Option[String],
publishResultsEnabled: Option[BrokerPublishData],
enablePending: Option[Boolean]
) {
def +(other: ScalaPactEnv): ScalaPactEnv =
ScalaPactEnv.append(this, other)
Expand Down Expand Up @@ -47,7 +48,17 @@ case class ScalaPactEnv(protocol: Option[String],
def enablePendingStatus: ScalaPactEnv = this.copy(enablePending = Some(true))

def toSettings: ScalaPactSettings =
ScalaPactSettings(protocol, host, port, localPactFilePath, strictMode, clientTimeout, outputPath, publishResultsEnabled, enablePending)
ScalaPactSettings(
protocol,
host,
port,
localPactFilePath,
strictMode,
clientTimeout,
outputPath,
publishResultsEnabled,
enablePending
)

}

Expand All @@ -65,7 +76,7 @@ object ScalaPactEnv {
Option(Duration(1, SECONDS)),
None, // "target/pacts"
None, // false
None // false
None // false
)

def defaults: ScalaPactEnv =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ object PactContractWriter {
}

()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ object ScalaPactStubberCommand {

def interactionManagerInstance: InteractionManager = new InteractionManager

def runStubber(scalaPactSettings: ScalaPactSettings, interactionManager: InteractionManager)(
implicit pactReader: IPactReader,
def runStubber(scalaPactSettings: ScalaPactSettings, interactionManager: InteractionManager)(implicit
pactReader: IPactReader,
pactWriter: IPactWriter,
pactStubber: IPactStubber,
sslContextMap: SslContextMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import scala.util.Try

object ScalaPactTestCommand {

def doPactPack(scalaPactSettings: ScalaPactSettings)(implicit pactReader: IPactReader,
pactWriter: IPactWriter): Unit = {
def doPactPack(
scalaPactSettings: ScalaPactSettings
)(implicit pactReader: IPactReader, pactWriter: IPactWriter): Unit = {
PactLogger.message("*************************************".white.bold)
PactLogger.message("** ScalaPact: Squashing Pact Files **".white.bold)
PactLogger.message("*************************************".white.bold)
Expand Down Expand Up @@ -45,8 +46,10 @@ object ScalaPactTestCommand {
}
}

private def squashPactFiles(outputPath: String, files: List[File])(implicit pactReader: IPactReader,
pactWriter: IPactWriter): Int = {
private def squashPactFiles(outputPath: String, files: List[File])(implicit
pactReader: IPactReader,
pactWriter: IPactWriter
): Int = {
val jsonStringToPact: String => Option[Pact] = pactReader.jsonStringToPact(_).toOption

val (failed, squashedPacts) =
Expand All @@ -68,7 +71,7 @@ object ScalaPactTestCommand {

private def fileToJsonString(file: File): Option[String] =
Try {
val source = Source.fromFile(file)
val source = Source.fromFile(file)
val contents = source.getLines().mkString
source.close()
file.delete()
Expand Down
Loading

0 comments on commit c4554a4

Please sign in to comment.