Skip to content

Commit

Permalink
more misc
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Oct 21, 2024
1 parent 5f3f5c3 commit c0bb187
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ case class FeatureRunner(featureDef: FeatureDef, baseFeature: BaseFeature, expli
case Left(afterFeatureError) => IO.raiseError(HooksFeatureError(beforeFeatureError, afterFeatureError).toException)
case Right(_) => IO.raiseError(beforeFeatureError.toException)
}
// Failed completely, nothing to cleanup, fast exit
// Failed completely, nothing to clean up, fast exit
case Left((beforeFeatureError, _)) => IO.raiseError(beforeFeatureError.toException)
case Right(_) =>
// `concurrentScenarios` is limited to avoid spawning too much work at once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sealed trait LogInstruction {
def colorized: String
lazy val fullMargin: String = LogInstruction.physicalMargin * marginNb
lazy val completeMessage: String = {
// Inject human readable duration at the end of the line
// Inject human-readable duration at the end of the line
def withMarginAndDuration(builder: StringBuilder, line: String): Unit = {
builder.append(fullMargin)
builder.append(line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class RunState(
lazy val goDeeper: RunState = copy(depth = depth + 1)
lazy val resetLogStack: RunState = copy(logStack = Nil)

// Helper fct to setup up a child nested context for a run which result must be merged back in using 'mergeNested'.
// Helper fct to set up up a child nested context for a run which result must be merged back in using 'mergeNested'.
// Only the session is propagated downstream as it is.
lazy val nestedContext: RunState = copy(depth = depth + 1, logStack = Nil, cleanupSteps = Nil)
lazy val sameLevelContext: RunState = copy(logStack = Nil, cleanupSteps = Nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ trait LogDecoratorStep extends Step {

// Without effect by default - wrapper steps usually build dynamically their title
def setTitle(newTitle: String): Step = this
def failedTitleLog(depth: Int) = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int) = SuccessLogInstruction(title, depth)
def failedTitleLog(depth: Int): FailureLogInstruction = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int): SuccessLogInstruction = SuccessLogInstruction(title, depth)
}

//Step that delegate the execution of nested steps and enable to inspect RunState and FailedStep
Expand Down Expand Up @@ -127,16 +127,16 @@ trait SimpleWrapperStep extends Step {

// Without effect by default - wrapper steps usually build dynamically their title
def setTitle(newTitle: String): Step = this
def failedTitleLog(depth: Int) = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int) = SuccessLogInstruction(title, depth)
def failedTitleLog(depth: Int): FailureLogInstruction = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int): SuccessLogInstruction = SuccessLogInstruction(title, depth)
}

//Step that gives full control over the execution of nested steps and their error reporting
trait WrapperStep extends Step {
// Without effect by default - wrapper steps usually build dynamically their title
def setTitle(newTitle: String): Step = this
def failedTitleLog(depth: Int) = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int) = SuccessLogInstruction(title, depth)
def failedTitleLog(depth: Int): FailureLogInstruction = FailureLogInstruction(title, depth)
def successTitleLog(depth: Int): SuccessLogInstruction = SuccessLogInstruction(title, depth)
}

// Describes the lifecycle of a resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Http4sClient(
case Right(uri) => EitherT {
val req = Request[IO](toHttp4sMethod(cReq.method))
val completeRequest = cReq.body.fold(req)(b => req.withEntity(b))
.putHeaders(toHttp4sHeaders(cReq.headers)) // `withEntity` adds `Content-Type` so we set the headers afterwards to have the possibility to override it
.putHeaders(toHttp4sHeaders(cReq.headers)) // `withEntity` adds `Content-Type` so we set the headers afterward to have the possibility to override it
.withUri(addQueryParams(uri, cReq.params))
val cornichonResponse = httpClient.run(completeRequest).use { http4sResp =>
http4sResp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ object JsonSteps {
sc.findAllMatchers(expectedShow).flatMap { matchers =>
if (matchers.nonEmpty) {
val withQuotedMatchers = Resolvable[A].transformResolvableForm(expected) { r =>
// don't add quotes if is not a complex JsonObject otherwise it would produce a double quoted string
// don't add quotes if is not a complex JsonObject otherwise it would produce a double-quoted string
if (isJsonString(r)) r
else MatcherResolver.quoteMatchers(r, matchers)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.collection.mutable.ListBuffer
object PlaceholderResolver {

private val rightNil = Right(Nil)
private val globalAtomicLong = new AtomicLong(1L) // can create non deterministic runs
private val globalAtomicLong = new AtomicLong(1L) // can create non-deterministic runs

def globalNextLong(): Long = globalAtomicLong.getAndIncrement()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ object ModelRunner {
def make[A](genA: RandomContext => Generator[A])(model: Model[A, NoValue, NoValue, NoValue, NoValue, NoValue]): ModelRunner[A, NoValue, NoValue, NoValue, NoValue, NoValue] =
ModelRunner(genA, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, model)

def make[A, B](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B])(model: Model[A, B, NoValue, NoValue, NoValue, NoValue]) =
def make[A, B](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B])(model: Model[A, B, NoValue, NoValue, NoValue, NoValue]): ModelRunner[A, B, NoValue, NoValue, NoValue, NoValue] =
ModelRunner(genA, genB, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, model)

def make[A, B, C](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C])(model: Model[A, B, C, NoValue, NoValue, NoValue]) =
def make[A, B, C](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C])(model: Model[A, B, C, NoValue, NoValue, NoValue]): ModelRunner[A, B, C, NoValue, NoValue, NoValue] =
ModelRunner(genA, genB, genC, seededNoValueGenerator, seededNoValueGenerator, seededNoValueGenerator, model)

def make[A, B, C, D](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D])(model: Model[A, B, C, D, NoValue, NoValue]) =
def make[A, B, C, D](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D])(model: Model[A, B, C, D, NoValue, NoValue]): ModelRunner[A, B, C, D, NoValue, NoValue] =
ModelRunner(genA, genB, genC, genD, seededNoValueGenerator, seededNoValueGenerator, model)

def make[A, B, C, D, E](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D], genE: RandomContext => Generator[E])(model: Model[A, B, C, D, E, NoValue]) =
def make[A, B, C, D, E](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D], genE: RandomContext => Generator[E])(model: Model[A, B, C, D, E, NoValue]): ModelRunner[A, B, C, D, E, NoValue] =
ModelRunner(genA, genB, genC, genD, genE, seededNoValueGenerator, model)

def make[A, B, C, D, E, F](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D], genE: RandomContext => Generator[E], genF: RandomContext => Generator[F])(model: Model[A, B, C, D, E, F]) =
def make[A, B, C, D, E, F](genA: RandomContext => Generator[A], genB: RandomContext => Generator[B], genC: RandomContext => Generator[C], genD: RandomContext => Generator[D], genE: RandomContext => Generator[E], genF: RandomContext => Generator[F])(model: Model[A, B, C, D, E, F]): ModelRunner[A, B, C, D, E, F] =
ModelRunner(genA, genB, genC, genD, genE, genF, model)

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case class AssertStep(title: String, action: ScenarioContext => Assertion, show:
def setTitle(newTitle: String): Step = copy(title = newTitle)

override def runLogValueStep(runState: RunState): IO[Either[NonEmptyList[CornichonError], Done]] = {
// IO.interruptible is much slower than IO.delay but it is needed to be able to cancel the execution of the assertion
// IO.interruptible is much slower than 'IO.delay' but it is needed to be able to cancel the execution of the assertion
IO.interruptible {
val assertion = action(runState.scenarioContext)
assertion.validated match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class RepeatDuringStep(nested: List[Step], duration: FiniteDuration) extend
if (remainingTime.gt(FiniteDuration(0, TimeUnit.MILLISECONDS)))
repeatStepsDuring(successState, remainingTime, retriesNumber + 1)
else
// In case of success all logs are returned but they are not printed by default.
// In case of success all logs are returned, but they are not printed by default.
IO.pure((retriesNumber, successState, rightDone))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case class RetryMaxStep(nested: List[Step], limit: Int) extends WrapperStep {
def retryMaxSteps(runState: RunState, limit: Int, retriesNumber: Long): IO[(Long, RunState, Either[FailedStep, Done])] =
ScenarioRunner.runStepsShortCircuiting(nested, runState.resetLogStack).flatMap {
case (retriedState, Left(_)) if limit > 0 =>
// In case of success all logs are returned but they are not printed by default.
// In case of success all logs are returned, but they are not printed by default.
retryMaxSteps(runState.recordLogStack(retriedState.logStack), limit - 1, retriesNumber + 1)

case (retriedState, l @ Left(_)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ case class WithinStep(nested: List[Step], maxDuration: Duration) extends Wrapper
case Right(_) =>
if (executionTime.gt(maxDuration)) {
val wrappedLogStack = FailureLogInstruction("Within block did not complete in time", initialDepth, Some(executionTime)) +: withinState.logStack :+ successTitleLog(initialDepth)
// The nested steps were successful but the did not finish in time, the last step is picked as failed step
// The nested steps were successful, but they did not finish in time, the last step is picked as failed step
val artificialFailedStep = FailedStep.fromSingle(nested.last, WithinBlockSucceedAfterMaxDuration(maxDuration, executionTime))
(wrappedLogStack, Left(artificialFailedStep))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class JsonStepsSpec extends FunSuite with CommonTestSuite {

test("JsonStepBuilder.is json without whitelisting enabled") {
val session = Session.newEmpty.addValuesUnsafe(testKey -> """{ "myKey" : "myValue", "myKeyOther" : "myOtherValue" }""")
// forcing whitelisting to false to have the negative test
// forcing whitelisting to 'false' to have the negative test
val step = jsonStepBuilder.copy(whitelist = false).is("""{ "myKeyOther" : "myOtherValue" }""")
val s = Scenario("scenario with JsonSteps", step :: Nil)
val res = awaitIO(ScenarioRunner.runScenario(session)(s))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.github.agourlay.cornichon.steps.regular.assertStep.{ AssertStep, Asse
object HttpListenSteps {

case class HttpListenStepBuilder(name: String) extends AnyVal {
def received_calls(count: Int) = AssertStep(
def received_calls(count: Int): AssertStep = AssertStep(
title = s"HTTP mock server '$name' received '$count' calls",
action = sc => Assertion.either {
sc.session.get(s"$name$nbReceivedCallsSuffix").map(c => GenericEqualityAssertion(count, c.toInt))
}
)

def received_requests =
def received_requests: JsonStepBuilder =
JsonStepBuilder(
SessionKey(s"$name$receivedBodiesSuffix"),
prettySessionKeyTitle = Some(s"HTTP mock server '$name' received requests")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ trait DeckSteps {

def scoreBlackjackHand(c1: String, c2: String): Int = scoreCards(c1) + scoreCards(c2)

// Yes I know "ACE" is 11 or 1 but we are having a simplified example for fun :)
// Yes I know "ACE" is 11 or 1, but we are having a simplified example for fun :)
def scoreCards(c: String): Int = c match {
case "1" => 1
case "2" => 2
Expand Down

0 comments on commit c0bb187

Please sign in to comment.