Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use new XML generator #487

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rust/pact_matching/src/generators/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use pact_models::path_exp::DocPath;
use pact_models::plugins::PluginData;
#[cfg(feature = "xml")] use pact_models::xml_utils::parse_bytes;

#[cfg(feature = "xml")] use crate::generators::XmlHandler;
#[cfg(feature = "xml")] use pact_models::generators::xml::XmlHandler;

#[cfg(feature = "form_urlencoded")] use pact_models::generators::form_urlencoded::FormUrlEncodedHandler;

Expand Down Expand Up @@ -168,10 +168,10 @@ mod tests {
}

#[tokio::test]
async fn do_not_apply_generator_to_xml_body_because_unimplemented() {
async fn apply_generator_to_xml_body_test() {
let body = OptionalBody::Present("<a>100</a>".into(), None, None);
expect!(generators_process_body(&GeneratorTestMode::Provider, &body, Some(XML.clone()),
&hashmap!{}, &hashmap!{DocPath::new_unwrap("$.name") => Generator::RandomInt(0, 10)}, &DefaultVariantMatcher{}, &vec![], &hashmap!{}).await.unwrap()).to(be_equal_to(body));
&hashmap!{}, &hashmap!{DocPath::new_unwrap("$.name") => Generator::RandomInt(0, 10)}, &DefaultVariantMatcher{}, &vec![], &hashmap!{}).await.unwrap()).to_not(be_equal_to(body));
}

#[tokio::test]
Expand Down
31 changes: 0 additions & 31 deletions rust/pact_matching/src/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,13 @@ use pact_models::v4::async_message::AsynchronousMessage;
use pact_models::v4::message_parts::MessageContents;
use pact_models::v4::sync_message::SynchronousMessage;
use serde_json::{self, Value};
#[cfg(feature = "xml")] use sxd_document::dom::Document;
use tracing::{debug, error, trace};

use crate::{CoreMatchingContext, DiffConfig, MatchingContext};
use crate::json::compare_json;

pub mod bodies;

/// Implementation of a content type handler for XML (currently unimplemented).
#[cfg(feature = "xml")]
pub struct XmlHandler<'a> {
/// XML document to apply the generators to.
pub value: Document<'a>
}

#[cfg(feature = "xml")]
impl <'a> pact_models::generators::ContentTypeHandler<Document<'a>> for XmlHandler<'a> {
fn process_body(
&mut self,
_generators: &HashMap<DocPath, Generator>,
_mode: &GeneratorTestMode,
_context: &HashMap<&str, Value>,
_matcher: &Box<dyn VariantMatcher + Send + Sync>
) -> Result<OptionalBody, String> {
error!("UNIMPLEMENTED: Generators are not currently supported with XML");
Err("Generators are not supported with XML".to_string())
}

fn apply_key(
&mut self,
_key: &DocPath,
_generator: &dyn GenerateValue<Document<'a>>,
_context: &HashMap<&str, Value>,
_matcher: &Box<dyn VariantMatcher + Send + Sync>
) {
error!("UNIMPLEMENTED: Generators are not currently supported with XML");
}
}

/// Apply the generators to the body, returning a new body
#[deprecated(note = "moved to the generators::bodies module", since = "0.12.16")]
Expand Down
Loading