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

Replace + with encoded value #22

Merged
merged 3 commits into from
Feb 28, 2024
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
48 changes: 27 additions & 21 deletions tests/scenarios/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ pub fn given_resource_in_system(
world: &mut DatadogWorld,
context: cucumber::step::Context,
) -> std::pin::Pin<Box<dyn futures::Future<Output = ()> + '_>> {

let mut given: Value = Value::Null;
let mut given_api_version: String = "".to_string();
let mut found = false;
Expand All @@ -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<String, Value> = HashMap::new();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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") {
Expand Down
Loading