Skip to content

Commit

Permalink
address a bunch of warnings and lints
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Jul 29, 2021
1 parent 0429f03 commit 963b324
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ To propose a patch, fork the repository and use the following commands:
A PR should ideally include:
- a clear description of the problem solved and of the solution implemented
- unit tests
- tests example of usage if the PR introduces changes in the DSL (e.g SuperHeroesScenario)
- tests example of usage if the PR introduces changes in the DSL (e.g. SuperHeroesScenario)
- an update to the documentation if necessary
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class FeatureRunner(featureDef: FeatureDef, baseFeature: BaseFeature, expli
case Right(_) =>
// featureParallelism is limited to avoid spawning too much work at once
val featureParallelism = if (baseFeature.executeScenariosInParallel) {
baseFeature.config.scenarioExecutionParallelismFactor * FeatureRunner.availaibleProcessors + 1
baseFeature.config.scenarioExecutionParallelismFactor * FeatureRunner.availableProcessors + 1
} else 1
Observable.fromIterable(scenariosToRun)
.mapParallelUnordered(featureParallelism)(runScenario(_).map(scenarioResultHandler))
Expand Down Expand Up @@ -84,6 +84,6 @@ case class FeatureRunner(featureDef: FeatureDef, baseFeature: BaseFeature, expli
}

object FeatureRunner {
lazy val availaibleProcessors: Int = Runtime.getRuntime.availableProcessors()
lazy val availableProcessors: Int = Runtime.getRuntime.availableProcessors()
private val noop = Task.now(Nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.github.agourlay.cornichon.steps.wrapped._
import monix.eval.Task

import scala.annotation.unchecked.uncheckedVariance
import scala.language.{ dynamics, higherKinds }
import scala.language.dynamics
import scala.concurrent.duration.FiniteDuration

trait CoreDsl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import scala.util.{ Failure, Success }
object DataTableParser {
val WhiteSpace = CharPredicate("\u0009\u0020")

val delimeter = CharPredicate('|')
val delimiterChar = CharPredicate('|')

val delims = CharPredicate(delimeter, '\r', '\n')
val delims = CharPredicate(delimiterChar, '\r', '\n')

val Backslash = CharPredicate('\\')

Expand Down Expand Up @@ -44,7 +44,7 @@ class DataTableParser(val input: ParserInput) extends Parser with StringHeaderPa

def Spaces = rule { quiet(zeroOrMore(DataTableParser.WhiteSpace)) }

def Separator = rule { Spaces ~ DataTableParser.delimeter ~ Spaces }
def Separator = rule { Spaces ~ DataTableParser.delimiterChar ~ Spaces }

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object HeadersSteps {
for {
sessionHeaders <- sc.session.get(lastResponseHeadersKey)
sessionHeadersValue <- HttpService.decodeSessionHeaders(sessionHeaders)
predicate <- Right(sessionHeadersValue.exists { case (hname, _) => hname.toLowerCase == name.toLowerCase })
predicate <- Right(sessionHeadersValue.exists { case (hName, _) => hName.toLowerCase == name.toLowerCase })
} yield CustomMessageEqualityAssertion(true, predicate, () => headersDoesNotContainFieldWithNameError(name, sessionHeadersValue))
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class JsonPathParser(val input: ParserInput) extends Parser {
(field, index) match {
case (JsonPath.root, None) => RootSelection
case (JsonPath.root, Some(i: Int)) => RootArrayElementSelection(i)
case (JsonPath.root, _) => RootArrayFieldProjection
case (f, None) => FieldSelection(f)
case (f, Some(i: Int)) => ArrayFieldSelection(f, i)
case (JsonPath.root, someStar @ _) => RootArrayFieldProjection
case (f, someStar @ _) => ArrayFieldProjection(f)
case (f, _) => ArrayFieldProjection(f)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object FeatureSpec extends TestSuite {
val tests = Tests {
test("a Feature have Scenarios with unique names") {
intercept[IllegalArgumentException] {
val f = FeatureDef("malformed feature", Scenario("doingstuff", Nil) :: Scenario("doingstuff", Nil) :: Nil)
val f = FeatureDef("malformed feature", Scenario("doing stuff", Nil) :: Scenario("doing stuff", Nil) :: Nil)
assert(f.name == "malformed feature") //never reached
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class SessionStepsProperties extends Properties("SessionSteps") with CommonTesti
forAll(Gen.alphaStr) { input =>
val session = Session.newEmpty
.addValuesUnsafe(testKey -> input)
val step = sessionStepBuilder.matchesRegex(s".*${input}42".r)
val unknownInput = input + "42"
val step = sessionStepBuilder.matchesRegex(s".*${unknownInput}".r)
val s = Scenario("scenario with SessionSteps", step :: Nil)
val t = awaitTask(ScenarioRunner.runScenario(session)(s))
if (t.isSuccess) printScenarioLogs(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object ScenarioResourceStepSpec extends TestSuite with CommonTestSuite {

val tests = Tests {
test("acquire a resource and release it before the end of the run even if something blows up in the middle") {
implicit val queueResource = new QueueManager
implicit val queueResource: QueueManager = new QueueManager
val resourceStep = ScenarioResourceStep(
"ensure queue exists",
createAndStoreQueueInSession("the-queue"),
Expand All @@ -31,7 +31,7 @@ object ScenarioResourceStepSpec extends TestSuite with CommonTestSuite {
}

test("not run a ResourceStep if a previous step failed but should still clean up the resource steps that did run") {
implicit val queueResource = new QueueManager
implicit val queueResource: QueueManager = new QueueManager
val resourceStep1 = ScenarioResourceStep("ensure q1 exists", createAndStoreQueueInSession("q1"), deleteQueue("q1"))
val resourceStep2 = ScenarioResourceStep("ensure q2 exists", createAndStoreQueueInSession("q2"), deleteQueue("q2"))
val scenario = Scenario("resource step scenario", resourceStep1 :: brokenEffectStep :: resourceStep2 :: Nil)
Expand All @@ -43,17 +43,17 @@ object ScenarioResourceStepSpec extends TestSuite with CommonTestSuite {

test("runs all the clean up steps in order") {
val is = List.range(1, 5)
implicit val queueResource = new QueueManager
implicit val queueResource: QueueManager = new QueueManager
val resourceSteps = is.map(i => ScenarioResourceStep(s"ensure q$i exists", createAndStoreQueueInSession(s"q$i"), deleteQueue(s"q$i")))
val scenario = Scenario("resource step scenario", resourceSteps)

val rep = awaitTask(ScenarioRunner.runScenario(Session.newEmpty)(scenario))
def q(i: Int) = rep.session.get(s"q$i").valueUnsafe
assert(queueResource.allActions == is.map(i => CreateQueue(q(i))) ++ is.reverse.map(i => DeleteQueue(q(i))))
assert(queueResource.allActions == is.map(i => CreateQueue(q(i))) ++ is.reverseIterator.map(i => DeleteQueue(q(i))))
}

test("perform all the release steps even if one fails and report all the ones that failed") {
implicit val queueResource = new QueueManager
implicit val queueResource: QueueManager = new QueueManager
val resourceStep1 = ScenarioResourceStep("ensure q1 exists", createAndStoreQueueInSession("q1"), deleteQueue("q1"))
val resourceStep2 = ScenarioResourceStep("ensure q2 exists", createAndStoreQueueInSession("q2"), failToDeleteQueue("q2"))
val resourceStep3 = ScenarioResourceStep("ensure q3 exists", createAndStoreQueueInSession("q3"), failToDeleteQueue("q3"))
Expand Down
11 changes: 6 additions & 5 deletions cornichon-docs/docs/custom-steps/effect-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This means that an `EffectStep` runs a side effect and populates the `Session` w

A `Session` is a Map-like object used to propagate state throughout a `scenario`. It is used to resolve [placeholders](../placeholders.md#placeholders) and save the result computations for later assertions.

Here is the most simple `EffectStep`:
Here is the simplest `EffectStep` possible:

```scala
When I EffectStep(title = "do nothing", action = scenarioContext => Future.successful(Right(scenarioContext.session)))
Expand All @@ -28,7 +28,7 @@ When I EffectStep.fromAsync(title = "do nothing", action = scenarioContext => Fu
Let's try to save a value into the `Session`

```scala
When I EffectStep.fromSync(title = "estimate PI", action = scenarioContext => scenarioContext.session.add("result", piComputation())
When I EffectStep.fromSync(title = "estimate PI", action = scenarioContext => scenarioContext.session.add("result", piComputation()))
```

The test engine is responsible for controlling the execution of the side effect function and to report any error.
Expand All @@ -45,20 +45,21 @@ val myTaskEffect = EffectStep("identity task", scenarioContext => Task.now(Right

# EffectStep using the HTTP service

Sometimes you want to perform HTTP calls inside of of an `EffectStep`, this is where the `httpService` comes in handy.
Sometimes you want to perform HTTP calls inside an `EffectStep`, this is where the `httpService` comes in handy.

In order to illustrate its usage let's take the following example, you would like to write a custom step like:

```scala
def feature = Feature("Customer endpoint"){
def feature = Feature("Customer endpoint") {

Scenario("create customer"){
Scenario("create customer") {

When I create_customer

Then assert status.is(201)

}
}
```

Most of the time you will create your own trait containing your custom steps and declare a self-type on `CornichonFeature` to be able to access the `httpService`.
Expand Down
2 changes: 1 addition & 1 deletion cornichon-docs/docs/custom-steps/resource-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def setup_some_fixture_data() = ScenarioResourceStep(
we can be sure the `clean up data` step runs regardless of what happens after `insert data`.

Multiple `SenarioResourceStep`s are allowed in a `Scenario`. In this case, the `release` `Step`
of the last `ScenarioResourceStep` is run first and we proceed up the `Scenario`.
of the last `ScenarioResourceStep` is run first, and we proceed up the `Scenario`.
6 changes: 3 additions & 3 deletions cornichon-docs/docs/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ session_value("favorite-superhero").is("Batman")
- asserting JSON value in `session`

```scala
session_value("my-json-response").asJson.path("a.b.c").ignoring("d").is(...)
session_value("my-json-response").asJson.path("a.b.c").ignoring("d").is("...")
```


Expand Down Expand Up @@ -408,7 +408,7 @@ Eventually(maxDuration = 15.seconds, interval = 200.milliseconds) {
}
```

It is also possible to enable the oscillations detector to fail the step in case of oscillation of errors.
It is also possible to enable the oscillation detector to fail the step in case of oscillation of errors.

```scala
Given I send_async_command_updating_search_index
Expand Down Expand Up @@ -507,7 +507,7 @@ There are two ways to perform assertions on the server statistics, either by que

Refer to those [examples](https://github.com/agourlay/cornichon-http-mock/blob/master/src/test/scala/com/github/agourlay/cornichon/examples/MockServerExample.scala) for more information.

This feature is experimental and subject to changes.
This feature is experimental and may change in the future.

- Log duration

Expand Down
14 changes: 9 additions & 5 deletions cornichon-docs/docs/feature-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ position: 7

# Feature options

To implement a `CornichonFeature` it is only required to implement the `feature` function. However a number of useful options are available using override.
To implement a `CornichonFeature` it is only required to implement the `feature` function. However, a number of useful options are available using override.

## Before and after hooks

Expand All @@ -17,9 +17,13 @@ Four functions are available in `CornichonFeature` with self-explanatory names:
Taking a `Unit` expression

```scala
beforeFeature { // do side effect here }
beforeFeature {
// do side effect here
}

afterFeature { // do side effect here }
afterFeature {
// do side effect here
}
```

Taking a `Step` expression similar to the main DSL. You can either pass a single regular `Step` or a `WrapperStep` like `Attach`.
Expand Down Expand Up @@ -111,7 +115,7 @@ It works for all keys in `Session`, let's say we also have objects registered un

## Execution model

By default the `features` are executed sequentially and the `scenarios` within are executed in parallel.
By default, the `features` are executed sequentially and the `scenarios` within are executed in parallel.

This execution is configurable if you have specific constraints.

Expand Down Expand Up @@ -164,7 +168,7 @@ class CornichonExamplesSpec extends CornichonFeature {

## Pending scenario

During development you want to remember that a `scenario` needs to be created, but you’re not ready to write it yet.
During development, you may want to remember that a `scenario` needs to be created, but you’re not ready to write it yet.

```scala mdoc:silent
import com.github.agourlay.cornichon.CornichonFeature
Expand Down
2 changes: 1 addition & 1 deletion cornichon-docs/docs/json-matchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Here are the available matchers:
- `*any-alphanum-string*` : checks if the field is an alpha-numeric String
- `*any-date*` : checks if the field is a 'yyyy-MM-dd' date
- `*any-date-time*` : checks if the field is a 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'' datetime
- `*any-time*` : checks if the field is a 'HH:mm:ss.SSS' time"
- `*any-time*` : checks if the field is a 'HH:mm:ss.SSS' time

This feature is still fresh and under experimentation therefore it comes with a couple of limitations:
- it is not yet possible to register custom JSON matchers
Expand Down
7 changes: 3 additions & 4 deletions cornichon-docs/docs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ For instance if you wish to use the `JsObject` from `play-json` as HTTP request'

```scala
lazy implicit val jsonResolvableForm = new Resolvable[JsObject] {
def toResolvableForm(s: JsObject) = s.toString()
def fromResolvableForm(s: String) = Json.parse(s).as[JsObject]
override def toResolvableForm(s: JsObject) = s.toString()
override def fromResolvableForm(s: String) = Json.parse(s).as[JsObject]
}

lazy implicit val showJson = new Show[JsObject] {
Expand Down Expand Up @@ -84,7 +84,7 @@ You can find below an example of Docker packaging done using `sbt-native-package

You can place these settings in a `docker.sbt` in the root of your project.

This should hopefully inspire you to setup your own solution or contribute to improve this one.
This should hopefully inspire you to set up your own solution or contribute to improve this one.

```scala
import NativePackagerHelper._
Expand All @@ -102,7 +102,6 @@ lazy val root = (project in file("."))

mappings in Universal ++= {
val testJar = (sbt.Keys.`package` in Test).value
val func = testJar -> s"lib/${testJar.getName}"
fromClasspath((managedClasspath in Test).value, "lib", _ => true) :+
(testJar -> s"lib/${testJar.getName}")
},
Expand Down
2 changes: 1 addition & 1 deletion cornichon-docs/docs/pbt/generators.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: "Generators"

At the center of property based testing lies the capacity to generate arbitrary values that will be used to verify if a given invariant holds.

A `generator` is simply a function that accepts a `RandomContext` which is propagated throughout the execution, for instance below is an example generating Strings and Ints.
A `generator` is simply a function that accepts a `RandomContext` which is propagated throughout the execution, for instance below is an example generating Strings and Integers.

There are tree concrete instances of `generators`:
- `ValueGenerator`
Expand Down
4 changes: 2 additions & 2 deletions cornichon-docs/docs/pbt/random-model-exploration.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ We will define the transitions such that:
- there is no loop from any `property`
- there is a 10% chance to exit the game after a ping or a pong

Also the DSL is asking for a `modelRunner` which is a little helper connecting a `model` to its `generators`.
Also, the DSL is asking for a `modelRunner` which is a little helper connecting a `model` to its `generators`.

The type inference is sometimes not properly detecting the action type, so it is recommended to define the `modelRunner` and the `model` as a single expression to help the typechecker.

Expand Down Expand Up @@ -126,7 +126,7 @@ Which gives us the following scenario

```scala

Scenario("ping pong check) {
Scenario("ping pong check") {

Given I check_model(maxNumberOfRuns = 2, maxNumberOfTransitions = 10)(myModelRunner)

Expand Down

0 comments on commit 963b324

Please sign in to comment.