Skip to content

Commit

Permalink
Sort query parameters properly so more scenarios are found by the com…
Browse files Browse the repository at this point in the history
…binator
  • Loading branch information
JordiPolo committed May 24, 2020
1 parent 7d639ef commit b13cffc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
28 changes: 13 additions & 15 deletions src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,23 @@ impl Mutator {
&self,
endpoint: &'a Endpoint,
mutations: &[Mutation],
query_mutations: &[Mutation],
query_mutations: &Vec<Vec<Mutation>>,
) -> Vec<Scenario<'a>> {
let mut scenarios = vec![];
let mut query_params: Vec<Vec<&Mutation>> = Vec::new();
let mut non_query_params: Vec<Vec<&Mutation>> = Vec::new();

debug!("QM size {:?}", query_mutations.len());
// TODO: CLI param to do or not do crazy amount of combinations.
// Group by request part or parameter so later can do combinations
// group_by only works well on sorted vectors
for (_key, group) in &query_mutations
.iter()
.sorted_by(|a, b| {
// Each vector has the mutations for one parameter and we do not care about that order
// But we care that 200 is at the top so we order by expedted
for mutations_vec in query_mutations {
let sorted = mutations_vec.iter().sorted_by(|a, b| {
Ord::cmp(
&a.payload, //param_value.as_ref().unwrap().name,
&b.payload,//param_value.as_ref().unwrap().name,
&a.mutagen.expected,
&b.mutagen.expected,
)
})
.group_by(|elt| &elt.payload) //param_value.as_ref().unwrap().name)
{
query_params.push(group.collect());
});
query_params.push(sorted.collect());
}

for (_key, group) in &mutations
Expand Down Expand Up @@ -198,6 +194,8 @@ impl Mutator {
combinations.push(temp);
}
}
} else {
println!("Could not find a passing scenario for {}. Consider adding information to the conversinons file", endpoint.path_name);
}

for combination in combinations {
Expand Down Expand Up @@ -328,7 +326,7 @@ impl Mutator {
fn mutations_from_mutagen_query(
&self,
endpoint: &Endpoint
) -> Vec<Mutation> {
) -> Vec<Vec<Mutation>> {
let mut params = Vec::new();
params.extend(endpoint.method.optional_parameters());
params.extend(endpoint.method.required_parameters());
Expand All @@ -339,7 +337,7 @@ impl Mutator {
} else {
Some(params::mutate(&param, &self.known_params).variations)
}}
).flatten().collect()
).collect()
}

fn mutations_from_mutagen(
Expand Down
1 change: 0 additions & 1 deletion src/mutation/param_mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::mutation::{Mutagen, Mutation};
use crate::request_param::RequestParam;
use openapi_utils::ParameterExt;
use crate::mutation::instructions::schema_mutagen;

pub struct ParamMutation {
pub variations: Vec<Mutation>,
pub param: openapiv3::Parameter,
Expand Down
1 change: 0 additions & 1 deletion src/mutation/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ pub fn mutate(param: &openapiv3::Parameter, known_params: &KnownParamCollection)
};
mutations.extend(typed_mutations);
}

mutations
}

0 comments on commit b13cffc

Please sign in to comment.