-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSuite.test.scala
65 lines (53 loc) · 2.02 KB
/
TestSuite.test.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package org.encalmo.aws
import scala.concurrent.duration.Duration
import scala.io.AnsiColor
class TestSuite extends munit.FunSuite {
override def munitTestTransforms: List[TestTransform] =
super.munitTestTransforms // ++ Seq(failFastTestTransform)
override val munitTimeout = Duration(30, "s")
final val debugModeProperties = Map("AWS_CLIENT_DEBUG_MODE" -> "ON")
final lazy val localAwsSecurityCredentials: Map[String, String] =
SetupAwsCredentials("encalmo-sandbox")
.map(_.toEnvironmentVariables)
.getOrElse(Map.empty)
final inline def assertMultipleTimes(test: => Unit): Unit =
(1 to 100).foreach(_ => test)
inline val BLUE_LIGHT = "\u001b[38;5;33m"
override def beforeEach(context: BeforeEach): Unit =
print(BLUE_LIGHT)
println("-" * 90)
println(
s"${this.getClass
.getSimpleName()}: ${BLUE_LIGHT}${AnsiColor.BOLD}${context.test.name}${AnsiColor.RESET}"
)
def dynamoDbDiff(startTag: String, endTag: String)(using stub: AwsClientStatefulStub): Option[String] =
for {
start <- stub.dynamoDb.getSnapshot(startTag)
end <- stub.dynamoDb.getSnapshot(endTag)
} yield new munit.diff.Diff(start, end).unifiedDiff
def failFastTestTransform: TestTransform =
new TestTransform(
"failFast",
{ t =>
t.withBodyMap {
_.transform(
identity,
e => {
try {
print(s"${AnsiColor.RESET}${AnsiColor.RED_B}${AnsiColor.WHITE}")
println(e)
e.getStackTrace().take(5).foreach(println)
println()
println(
s"${getClass.getName} ${AnsiColor.BOLD}${t.name}${AnsiColor.RESET}${AnsiColor.RED_B}${AnsiColor.WHITE} at ${t.location}${AnsiColor.RESET}"
)
println()
} catch { case _ => () /*ignore*/ }
if (System.getenv("TESTS_DO_NOT_FAIL_FAST") == null) then System.exit(2)
e
}
)(munitExecutionContext)
}
}
)
}