Added support for referencing file contents in the contract (#360)
without this change, large bodies can't be parsed by the compiler with this change we allow those bodies to be read from files fixes #357
This commit is contained in:
committed by
GitHub
parent
cf4131ad17
commit
4de7d38a51
@@ -67,6 +67,48 @@ or just set the `ignored` property on the contract itself:
|
||||
include::{contract_spec_path}/src/test/groovy/org/springframework/cloud/contract/spec/internal/ContractSpec.groovy[tags=ignored,indent=0]
|
||||
----
|
||||
|
||||
===== Passing values from files
|
||||
|
||||
Starting with version `1.2.0` it's possible to pass values from files. Let's assume that we have
|
||||
the following resources in our project.
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
└── src
|
||||
└── test
|
||||
└── resources
|
||||
└── contracts
|
||||
├── readFromFile.groovy
|
||||
├── request.json
|
||||
└── response.json
|
||||
----
|
||||
|
||||
And our contract looks like this:
|
||||
|
||||
[source,groovy,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/resources/classpath/readFromFile.groovy[indent=0]
|
||||
----
|
||||
|
||||
and the json files look like this:
|
||||
|
||||
*request.json*
|
||||
[source,json,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/resources/classpath/request.json[indent=0]
|
||||
----
|
||||
|
||||
*response.json*
|
||||
[source,json,indent=0]
|
||||
----
|
||||
include::{verifier_core_path}/src/test/resources/classpath/response.json[indent=0]
|
||||
----
|
||||
|
||||
When test / stub generation takes place then the contents of the file will be
|
||||
passed to the body of request / response. All thanks to the `file(...)` method.
|
||||
The argument of that method needs to be a file with location relative to the
|
||||
folder in which the contract lays.
|
||||
|
||||
==== HTTP Top-Level Elements
|
||||
|
||||
Following methods can be called in the top-level closure of a contract definition. Request and response are mandatory, priority is optional.
|
||||
|
||||
@@ -878,3 +878,8 @@ started will be attached.
|
||||
|
||||
Yes! With version 1.1.0 we've added such a possibility. On the HTTP stub server side we're providing support
|
||||
for this for WireMock. In case of other HTTP server stubs you'll have to implement the approach yourself.
|
||||
|
||||
==== Can I reference text from file?
|
||||
|
||||
Yes! With version 1.2.0 we've added such a possibility. It's enough to call `file(...)` method in the
|
||||
DSL and provide a path relative to where the contract lays.
|
||||
|
||||
Reference in New Issue
Block a user