diff --git a/Cargo.toml b/Cargo.toml index af7ea2e78..3a9a62757 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ sha256 = "1.4.0" tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] } minijinja = "1.0.10" convert_case = "0.6.0" +urlencoding = "2.1.3" [[test]] harness = false # allows Cucumber to print output instead of libtest diff --git a/tests/main.rs b/tests/main.rs index db55bc3b0..bdcd5a866 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -34,10 +34,7 @@ lazy_static! { let given_v2: Value = serde_json::from_reader(BufReader::new(given_v2_file)) .expect("failed to deserialize given.json"); - HashMap::from([ - ("v1".to_string(), givens_v1), - ("v2".to_string(), given_v2), - ]) + HashMap::from([("v1".to_string(), givens_v1), ("v2".to_string(), given_v2)]) }; pub static ref UNDO_MAP: Value = { let undo_v1_file = File::open("tests/scenarios/features/v1/undo.json").unwrap(); diff --git a/tests/scenarios/fixtures.rs b/tests/scenarios/fixtures.rs index c124f0c77..0136cde28 100644 --- a/tests/scenarios/fixtures.rs +++ b/tests/scenarios/fixtures.rs @@ -261,7 +261,6 @@ pub fn given_resource_in_system( world: &mut DatadogWorld, context: cucumber::step::Context, ) -> std::pin::Pin + '_>> { - let mut given: Value = Value::Null; let mut given_api_version: String = "".to_string(); let mut found = false; @@ -282,7 +281,7 @@ pub fn given_resource_in_system( if !found { panic!("given step not found"); } - + let given_key = given.get("key").unwrap().as_str().unwrap().to_string(); Box::pin(async move { let mut given_parameters: HashMap = HashMap::new(); @@ -564,20 +563,31 @@ fn response_is_bool(world: &mut DatadogWorld, path: String, expected: String) { } fn req_eq(lhs: &vcr_cassette::Request, rhs: &vcr_cassette::Request) -> bool { - let lhs_queries: HashSet<_> = lhs - .uri - .query() - .unwrap_or_default() - .split("&") - .into_iter() - .collect(); - let rhs_queries: HashSet<_> = rhs - .uri - .query() - .unwrap_or_default() - .split("&") - .into_iter() - .collect(); + let lhs_query = urlencoding::decode( + lhs.uri + .query() + .unwrap_or_default() + .to_string() + .replace("+", "%20") + .as_str(), + ) + .expect("UTF-8") + .to_string(); + + let rhs_query = urlencoding::decode( + rhs.uri + .query() + .unwrap_or_default() + .to_string() + .replace("+", "%20") + .as_str(), + ) + .expect("UTF-8") + .to_string(); + + let lhs_queries: HashSet<_> = lhs_query.split("&").into_iter().collect(); + let rhs_queries: HashSet<_> = rhs_query.split("&").into_iter().collect(); + lhs.uri.scheme() == rhs.uri.scheme() && lhs.uri.host() == rhs.uri.host() && lhs.uri.port() == rhs.uri.port() @@ -740,11 +750,7 @@ fn build_undo( if world.response.code < 200 || world.response.code >= 300 { return Ok(None); } - let undo = UNDO_MAP - .get(operation_id) - .unwrap() - .get("undo") - .unwrap(); + let undo = UNDO_MAP.get(operation_id).unwrap().get("undo").unwrap(); match undo.get("type").unwrap().as_str() { Some("unsafe") => { let api_name = if let Some(tag) = undo.get("tag") {