Created
June 13, 2020 14:25
-
-
Save andyczerwonka/206043f615ffb5cd35e7f80cbca2fe54 to your computer and use it in GitHub Desktop.
Discussion around an API that could collect failures and success
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.citrine.orion.core.domain | |
import io.citrine.testing.BaseUnitTest | |
import scala.collection.mutable.ListBuffer | |
class BusinessRuleTest extends BaseUnitTest { | |
trait StatusInfo { | |
def write(msg: String) | |
def msgs(): Seq[String] | |
} | |
class StatusInfoWriter extends StatusInfo { | |
private val buffer = ListBuffer[String]() | |
override def write(msg: String): Unit = buffer += msg | |
override def msgs(): List[String] = buffer.toList | |
} | |
implicit val statusInfo = new StatusInfoWriter | |
case class Row(contents: String) | |
def rule(desc: String)(predicate: => Boolean)(implicit statusInfo: StatusInfo): Boolean = { | |
val ex = predicate | |
val prefix = if (ex) "Passed:" else "Failed:" | |
statusInfo.write(s"$prefix $desc") | |
ex | |
} | |
test("allow less than 100 rows") { | |
val rows = List(Row("1")) | |
rule("Limit rows to 100") { | |
rows.length < 100 | |
} shouldBe true | |
statusInfo.msgs contains ("Passed: Limit rows to 100") | |
} | |
test("fail when rows > 100") { | |
val rows = for (i <- 0 to 101) yield Row(s"$i") | |
rule("Limit rows to 100") { | |
rows.length < 100 | |
} shouldBe false | |
statusInfo.msgs contains ("Failed: Limit rows to 100") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just pondering ideas attempting to separate the traceability use case (recording the fact a test passed vs failed) from writing rules, and ways of integrating it into other validation frameworks like Octopus or Accord, which don't support it.