Skip to content

Commit

Permalink
Added test for generating examples containing pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrosario committed Jun 16, 2020
1 parent 88ef989 commit f235d3b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions core/src/test/kotlin/run/qontract/core/ContractAsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,50 @@ And response-body
assertThat(results.failureCount).isZero()
assertThat(results.successCount).isNotZero()
}
@Test
fun `should generate data with a pipe when the example contains a pipe`() {
val gherkin = """
Feature: Contract
Scenario: api call
Given POST /
And request-body
| data | (string) |
Then status 200
Examples:
| data |
| 1\|2\|3 |
"""

val flags = mutableListOf<String>()

val results = Feature(gherkin).executeTests(object : TestExecutor {
override fun execute(request: HttpRequest): HttpResponse {
val body = request.body
if(body !is JSONObjectValue)
fail("Expected json object")

val data = body.jsonObject.getValue("data")
assertThat(data).isInstanceOf(StringValue::class.java)
assertThat(data.toStringValue()).isEqualTo("1|2|3")

flags.add("ran")

return HttpResponse.OK
}

override fun setServerState(serverState: Map<String, Value>) {

}
})

println(results.report())

assertThat(results.failureCount).isZero()
assertThat(results.successCount).isOne()

assertThat(flags.toList()).isEqualTo(listOf("ran"))
}
}

internal fun jsonObject(value: Value?): Map<String, Value> {
Expand Down

0 comments on commit f235d3b

Please sign in to comment.