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

fix(types): warn on unknown interface #536

Merged
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
29 changes: 8 additions & 21 deletions crates/wadm-types/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ fn is_invalid_known_interface(
};
// Unknown interface inside known namespace and package is probably a bug
if !iface_lookup.contains_key(interface) {
// Unknown package inside a known interface we control is probably a bug
// Unknown package inside a known interface we control is probably a bug, but may be
// a new interface we don't know about yet
return vec![ValidationFailure::new(
ValidationFailureLevel::Error,
ValidationFailureLevel::Warning,
format!("unrecognized interface [{namespace}:{package}/{interface}]"),
)];
}
Expand Down Expand Up @@ -702,38 +703,24 @@ pub fn validate_link_configs(manifest: &Manifest) -> Vec<ValidationFailure> {
let mut failures = Vec::new();
let mut link_config_names = HashSet::new();
for link_trait in manifest.links() {
if let TraitProperty::Link(LinkProperty {
target,
source,
..
}) = &link_trait.properties {
if let TraitProperty::Link(LinkProperty { target, source, .. }) = &link_trait.properties {
for config in target.config.iter() {
// Check if config name is unique
if !link_config_names.insert((
config.name.clone(),
)) {
if !link_config_names.insert((config.name.clone(),)) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!(
"Duplicate link config name found: '{}'",
config.name
),
format!("Duplicate link config name found: '{}'", config.name),
));
}
}

if let Some(source) = source {
for config in source.config.iter() {
// Check if config name is unique
if !link_config_names.insert((
config.name.clone(),
)) {
if !link_config_names.insert((config.name.clone(),)) {
failures.push(ValidationFailure::new(
ValidationFailureLevel::Error,
format!(
"Duplicate link config name found: '{}'",
config.name
),
format!("Duplicate link config name found: '{}'", config.name),
));
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ async fn validate_misnamed_interface() -> Result<()> {
!failures.is_empty()
&& failures
.iter()
.all(|f| f.level == ValidationFailureLevel::Error),
"failures present, all errors"
.all(|f| f.level == ValidationFailureLevel::Warning),
"failures present, all warnings"
);
assert!(
!failures.valid(),
"manifest should be invalid (misnamed interface w/ right namespace & package is probably a bug)"
failures.valid(),
"manifest should be valid (misnamed interface w/ right namespace & package is probably a bug but might be intentional)"
);
Ok(())
}
Expand Down Expand Up @@ -126,19 +126,19 @@ async fn validate_link_config_names() -> Result<()> {
validate_manifest_file("./tests/fixtures/manifests/duplicate_link_config_names.wadm.yaml")
.await
.context("failed to validate manifest")?;
let expected_errors = 3;
assert!(
let expected_errors = 3;
assert!(
!failures.is_empty()
&& failures
.iter()
.all(|f| f.level == ValidationFailureLevel::Error)
&& failures.len() == expected_errors,
"expected {} errors because manifest contains {} duplicated link config names, instead {} errors were found", expected_errors, expected_errors, failures.len().to_string()
);
assert!(
!failures.valid(),
"manifest should be invalid (duplicated link config names lead to a dead loop)"
);
assert!(
!failures.valid(),
"manifest should be invalid (duplicated link config names lead to a dead loop)"
);
Ok(())
}

Expand Down