Skip to content

Commit 111a18c

Browse files
committed
Feat(pact_consumer): Upgrade pact_mock_server to the new 2.0.0 version
1 parent fd1ba0c commit 111a18c

File tree

16 files changed

+380
-243
lines changed

16 files changed

+380
-243
lines changed

rust/Cargo.lock

Lines changed: 81 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/pact_consumer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pact_consumer"
3-
version = "1.2.4"
3+
version = "1.3.0"
44
authors = ["Ronald Holshausen <ronald.holshausen@gmail.com>", "Eric Kidd <git@randomhacks.net>"]
55
edition = "2021"
66
description = "Pact-Rust module that provides support for writing consumer pact tests"
@@ -31,7 +31,7 @@ itertools = "0.13.0"
3131
lazy_static = "1.5.0"
3232
maplit = "1.0.2"
3333
pact_matching = { version = "~1.2.5", path = "../pact_matching", default-features = false }
34-
pact_mock_server = { version = "~1.2.9", default-features = false }
34+
pact_mock_server = { version = "~2.0.0", default-features = false }
3535
pact_models = { version = "~1.2.2", default-features = false }
3636
pact-plugin-driver = { version = "~0.7.0", optional = true, default-features = false }
3737
regex = "1.10.5"

rust/pact_consumer/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ To use it, add it to your dev-dependencies in your cargo manifest:
1212

1313
```toml
1414
[dev-dependencies]
15-
pact_consumer = "1.1"
15+
pact_consumer = "1.3"
1616
```
1717

1818
You can now write a pact test using the consumer DSL.
1919

2020
```rust
2121
use pact_consumer::prelude::*;
22-
use pact_consumer::*;
2322

2423
#[tokio::test]
2524
async fn a_service_consumer_side_of_a_pact_goes_a_little_something_like_this() {
@@ -76,7 +75,6 @@ file.
7675

7776
```rust
7877
use pact_consumer::prelude::*;
79-
use pact_consumer::*;
8078

8179
#[test]
8280
fn a_message_consumer_side_of_a_pact_goes_a_little_something_like_this() {
@@ -120,7 +118,6 @@ one or more response messages are returned. Examples of this would be things lik
120118

121119
```rust
122120
use pact_consumer::prelude::*;
123-
use pact_consumer::*;
124121
use expectest::prelude::*;
125122
use serde_json::{Value, from_slice};
126123

rust/pact_consumer/src/builders/pact_builder.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt::{Debug, Formatter};
22
use std::panic::RefUnwindSafe;
33
use std::path::PathBuf;
4+
use pact_mock_server::mock_server::MockServerConfig;
45

56
use pact_models::{Consumer, Provider};
67
use pact_models::interaction::Interaction;
@@ -282,7 +283,11 @@ impl PactBuilder {
282283
}
283284

284285
impl StartMockServer for PactBuilder {
285-
fn start_mock_server(&self, _catalog_entry: Option<&str>) -> Box<dyn ValidatingMockServer> {
286+
fn start_mock_server(
287+
&self,
288+
_catalog_entry: Option<&str>,
289+
mock_server_config: Option<MockServerConfig>
290+
) -> Box<dyn ValidatingMockServer> {
286291
#[cfg(feature = "plugins")]
287292
{
288293
match _catalog_entry {
@@ -295,13 +300,13 @@ impl StartMockServer for PactBuilder {
295300
}
296301
None => panic!("Did not find a catalogue entry for key '{}'", entry_name)
297302
}
298-
None => ValidatingHttpMockServer::start(self.build(), self.output_dir.clone())
303+
None => ValidatingHttpMockServer::start(self.build(), self.output_dir.clone(), mock_server_config)
299304
}
300305
}
301306

302307
#[cfg(not(feature = "plugins"))]
303308
{
304-
ValidatingHttpMockServer::start(self.build(), self.output_dir.clone())
309+
ValidatingHttpMockServer::start(self.build(), self.output_dir.clone(), mock_server_config)
305310
}
306311
}
307312
}

rust/pact_consumer/src/builders/pact_builder_async.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::future::Future;
22
use std::path::PathBuf;
33

44
use async_trait::async_trait;
5+
use pact_mock_server::mock_server::MockServerConfig;
56
use pact_models::{Consumer, Provider};
67
use pact_models::interaction::Interaction;
78
use pact_models::pact::Pact;
@@ -251,7 +252,11 @@ impl PactBuilderAsync {
251252
}
252253

253254
impl StartMockServer for PactBuilderAsync {
254-
fn start_mock_server(&self, _catalog_entry: Option<&str>) -> Box<dyn ValidatingMockServer> {
255+
fn start_mock_server(
256+
&self,
257+
_catalog_entry: Option<&str>,
258+
mock_server_config: Option<MockServerConfig>
259+
) -> Box<dyn ValidatingMockServer> {
255260
#[cfg(feature = "plugins")]
256261
{
257262
match _catalog_entry {
@@ -264,20 +269,24 @@ impl StartMockServer for PactBuilderAsync {
264269
}
265270
None => panic!("Did not find a catalogue entry for key '{}'", entry_name)
266271
}
267-
None => ValidatingHttpMockServer::start(self.build(), self.output_dir.clone())
272+
None => ValidatingHttpMockServer::start(self.build(), self.output_dir.clone(), mock_server_config)
268273
}
269274
}
270275

271276
#[cfg(not(feature = "plugins"))]
272277
{
273-
ValidatingHttpMockServer::start(self.build(), self.output_dir.clone())
278+
ValidatingHttpMockServer::start(self.build(), self.output_dir.clone(), mock_server_config)
274279
}
275280
}
276281
}
277282

278283
#[async_trait]
279284
impl StartMockServerAsync for PactBuilderAsync {
280-
async fn start_mock_server_async(&self, _catalog_entry: Option<&str>) -> Box<dyn ValidatingMockServer> {
285+
async fn start_mock_server_async(
286+
&self,
287+
_catalog_entry: Option<&str>,
288+
mock_server_config: Option<MockServerConfig>
289+
) -> Box<dyn ValidatingMockServer> {
281290
#[cfg(feature = "plugins")]
282291
{
283292
match _catalog_entry {
@@ -290,13 +299,13 @@ impl StartMockServerAsync for PactBuilderAsync {
290299
}
291300
None => panic!("Did not find a catalogue entry for key '{}'", entry_name)
292301
}
293-
None => ValidatingHttpMockServer::start_async(self.build(), self.output_dir.clone()).await
302+
None => ValidatingHttpMockServer::start_async(self.build(), self.output_dir.clone(), mock_server_config).await
294303
}
295304
}
296305

297306
#[cfg(not(feature = "plugins"))]
298307
{
299-
ValidatingHttpMockServer::start_async(self.build(), self.output_dir.clone()).await
308+
ValidatingHttpMockServer::start_async(self.build(), self.output_dir.clone(), mock_server_config).await
300309
}
301310
}
302311
}

rust/pact_consumer/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
//! // Return the interaction builder back to the pact framework
5858
//! i
5959
//! })
60-
//! .start_mock_server(None);
60+
//! .start_mock_server(None, None);
6161
//! ```
6262
//!
6363
//! You can than use an HTTP client like `reqwest` to make requests against your
@@ -82,7 +82,7 @@
8282
//! # .body("That is some good Mallory.");
8383
//! # // Return the interaction builder back to the pact framework
8484
//! # i
85-
//! # }).start_mock_server(None);
85+
//! # }).start_mock_server(None, None);
8686
//!
8787
//! // You would use your actual client code here.
8888
//! let mallory_url = provider_service.path("/mallory");
@@ -104,7 +104,6 @@
104104
//!
105105
//! ```
106106
//! use pact_consumer::prelude::*;
107-
//! use pact_consumer::*;
108107
//!
109108
//! PactBuilder::new("quotes client", "quotes service")
110109
//! .interaction("add a new quote to the database", "", |mut i| {
@@ -156,7 +155,6 @@
156155
//!
157156
//! ```
158157
//! use pact_consumer::prelude::*;
159-
//! use pact_consumer::{each_like, each_like_helper, json_pattern};
160158
//! use serde::{Deserialize, Serialize};
161159
//!
162160
//! /// Our application's domain object representing a user.
@@ -210,7 +208,6 @@
210208
//!
211209
//! ```rust
212210
//! use pact_consumer::prelude::*;
213-
//! use pact_consumer::*;
214211
//! use expectest::prelude::*;
215212
//! use serde_json::{Value, from_slice};
216213
//!
@@ -348,7 +345,7 @@
348345
//! })
349346
//! .await
350347
//! // Now start the mock server
351-
//! .start_mock_server_async(None)
348+
//! .start_mock_server_async(None, None)
352349
//! .await;
353350
//!
354351
//! // Now we can make our actual request for the CSV file and validate the response
@@ -392,6 +389,14 @@ pub mod util;
392389
/// use pact_consumer::prelude::*;
393390
/// ```
394391
pub mod prelude {
392+
pub use crate::{
393+
like,
394+
each_like,
395+
each_like_helper,
396+
term,
397+
json_pattern,
398+
json_pattern_internal
399+
};
395400
pub use crate::builders::{HttpPartBuilder, PactBuilder, PactBuilderAsync};
396401
#[cfg(feature = "plugins")] pub use crate::builders::plugin_builder::PluginInteractionBuilder;
397402
pub use crate::mock_server::{StartMockServer, ValidatingMockServer};
@@ -410,6 +415,7 @@ pub mod prelude {
410415
};
411416
#[cfg(feature = "datetime")] pub use crate::patterns::{DateTime};
412417
pub use crate::util::strip_null_fields;
418+
pub use pact_mock_server::mock_server::MockServerConfig;
413419
}
414420

415421
/// Consumer version

0 commit comments

Comments
 (0)