Permalink
Browse files

Use log4s in test (JVM/JS) and log test exceptions

  • Loading branch information...
lefou committed Dec 3, 2018
1 parent 7e777d6 commit 617229266cc74c3f1eccbd39e77320f951d52b4d
@@ -4,6 +4,7 @@ import java.util.UUID
import scala.reflect.{ClassTag, classTag}
import scala.util.Success
import scala.util.control.NonFatal
import blended.updater.config.json.PrickleProtocol._
import org.scalacheck.Arbitrary
@@ -13,8 +14,10 @@ import prickle._
class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
private[this] val log = org.log4s.getLogger
"Prickle real world test cases" - {
"1. deserialize a container info" in {
"1. deserialize a container info" in logException {
val svcInfos = List(
ServiceInfo(
@@ -86,7 +89,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
}
"Prickle should (de)serialize" - {
"an ActivateProfile" in {
"an ActivateProfile" in logException {
val overlay = OverlayRef("myOverlay", "1.0")
val action = ActivateProfile(UUID.randomUUID().toString(), profileName = "test", profileVersion = "1.0", overlays = Set(overlay))
@@ -105,7 +108,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
}
"an ActivateProfile as UpdateAction" in {
"an ActivateProfile as UpdateAction" in logException {
val overlay = OverlayRef("myOverlay", "1.0")
val action = ActivateProfile(UUID.randomUUID().toString(), profileName = "test", profileVersion = "1.0", overlays = Set(overlay))
@@ -124,7 +127,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
activate.overlays should be(Set(overlay))
}
"a GeneratedConfig" in {
"a GeneratedConfig" in logException {
val cfg = GeneratedConfig("filename", "{ key1: value1 }")
val json = Pickle.intoString(cfg)
@@ -133,7 +136,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
}
"a ServiceInfo" in {
"a ServiceInfo" in logException {
val svcInfo = ServiceInfo("mySvc", "myType", System.currentTimeMillis(), 1000l, Map("svc" -> "test"))
@@ -145,7 +148,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
svc should be(svcInfo)
}
"a list of ServiceInfo's" in {
"a list of ServiceInfo's" in logException {
val svcInfo = ServiceInfo("mySvc", "myType", System.currentTimeMillis(), 1000l, Map("svc" -> "test"))
@@ -157,7 +160,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
svcList should be(List(svcInfo))
}
"a ContainerInfo" in {
"a ContainerInfo" in logException {
val svcInfo = ServiceInfo("mySvc", "myType", System.currentTimeMillis(), 1000l, Map("svc" -> "test"))
val profile = Profile("myProfile", "1.0", OverlaySet(Set(), OverlayState.Valid, None))
@@ -176,7 +179,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
info2.profiles should be(List(profile))
}
"a ContainerRegistryResponseOK" in {
"a ContainerRegistryResponseOK" in logException {
val resp = ContainerRegistryResponseOK("response", List.empty)
val json = Pickle.intoString(resp)
@@ -187,7 +190,7 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
}
"a RemoteContainerState" in {
"a RemoteContainerState" in logException {
val svcInfo = ServiceInfo("mySvc", "myType", System.currentTimeMillis(), 1000l, Map("svc" -> "test"))
val profile = Profile("myProfile", "1.0", OverlaySet(Set(), OverlayState.Valid, None))
@@ -216,9 +219,11 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
arb: Arbitrary[T],
u: Unpickler[T],
p: Pickler[T]): Unit = {
classTag[T].runtimeClass.getSimpleName in {
classTag[T].runtimeClass.getSimpleName in logException {
forAll { d: T =>
assert(Unpickle[T].fromString(Pickle.intoString(d)) === Success(d))
val backAndForth = Unpickle[T].fromString(Pickle.intoString(d))
// log.info(s"data: [${backAndForth}]")
assert(backAndForth === Success(d))
}
}
}
@@ -243,9 +248,12 @@ class PrickleSpec extends FreeSpec with Matchers with PropertyChecks {
// testMapping(mapRemoteContainerState, unmapRemoteContainerState)
}
// As the test runs also in JS, we cannot use a SLF4J
def log = new {
def info(msg: => String) = println(msg)
def logException[T](f: => T): T = try {
f
} catch {
case NonFatal(e) =>
log.error(e)("Exception caught")
throw e
}
}
@@ -23,7 +23,8 @@ object BlendedUpdaterConfigJs extends ProjectFactory {
libraryDependencies ++= Seq(
"com.github.benhutchison" %%% "prickle" % Dependencies.prickleVersion,
"org.scalatest" %%% "scalatest" % Dependencies.scalatestVersion % "test",
"org.scalacheck" %%% "scalacheck" % Dependencies.scalacheck.revision % "test"
"org.scalacheck" %%% "scalacheck" % Dependencies.scalacheck.revision % "test",
"org.log4s" %%% "log4s" % Dependencies.log4s.revision % "test"
)
)
)
@@ -45,7 +46,8 @@ object BlendedUpdaterConfigJvm extends ProjectFactory {
Dependencies.scalatest % "test",
Dependencies.logbackClassic % "test",
Dependencies.logbackCore % "test",
Dependencies.scalacheck % "test"
Dependencies.scalacheck % "test",
Dependencies.log4s % "test"
),
adaptBundle = b => b.copy(
exportPackage = Seq(
@@ -87,6 +87,8 @@ object Dependencies {
val levelDbJava = "org.iq80.leveldb" % "leveldb" % "0.9"
val levelDbJni = "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.8"
val liquibase = "org.liquibase" % "liquibase-core" % "3.6.1"
/** Only for use in test that also runs in JS */
val log4s = "org.log4s" %% "log4s" % "1.6.1"
val logbackCore = "ch.qos.logback" % "logback-core" % "1.2.3"
val logbackClassic = "ch.qos.logback" % "logback-classic" % "1.2.3"

0 comments on commit 6172292

Please sign in to comment.