Skip to content

Commit

Permalink
fix(validatation): deeply nested loops
Browse files Browse the repository at this point in the history
Signed-off-by: Márk Kővári <[email protected]>
  • Loading branch information
markkovari committed Jul 17, 2024
1 parent de08cc2 commit f8a269d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
39 changes: 17 additions & 22 deletions crates/wadm-types/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,28 +408,23 @@ fn check_dangling_links(manifest: &Manifest) -> Vec<ValidationFailure> {
fn check_source_config_on_components(manifest: &Manifest) -> Vec<ValidationFailure> {
let forbidden_config_key = "source_config";
let mut failures = Vec::new();
let components = manifest.components();
for component in components {
for component_traits in component.traits.iter() {
for component_trait in component_traits {
match &component_trait.properties {
TraitProperty::Custom(custom) => {
match custom {
Value::Object(custom_trait_config) => {
if custom_trait_config.contains_key(forbidden_config_key) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!(
"source_config found on one of the component: {}'s traits properties",
component.name
),
))
}
}
_ => {}
}
}
_ => {}
let components = manifest.component_lookup();
let component_traits = components
.into_iter()
.filter_map(|(name, component)| match &component.traits {
Some(traits) => Some((name, traits)),
None => None,
});
for (name, traits) in component_traits {
for trait_ in traits {
if let TraitProperty::Custom(custom) = trait_.properties.clone() {
if let Some(_) = custom.get(forbidden_config_key) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!(
"component [{name}] has source_config in one of its traits properties",
),
))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async fn validate_source_config_on_component_errors() -> Result<()> {
);
assert_eq!(
msg,
"source_config found on one of the component: http-component's traits properties",
"component [http-component] has source_config in one of its traits properties",
"expected error message, but was incorrect",
);
Ok(())
Expand Down

0 comments on commit f8a269d

Please sign in to comment.