-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add test 6.1.31 #232
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9cafd5b
feat: add test 6.1.31
peinjoh 001ea7d
fix: clippy
peinjoh a609560
refactor: improve return type
peinjoh 4ed24bf
Merge branch 'main' into feat/114-test-6-1-31
peinjoh 7145038
Merge branch 'main' into feat/114-test-6-1-31
peinjoh de224dc
fix: split on all unicode whitespaces
peinjoh b486584
fix: migrate to new test infra, support multiple offending tokens
peinjoh d3594b3
format: fmt
peinjoh 21d35c2
Correct comment placement
peinjoh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| use crate::csaf_traits::{BranchTrait, CsafTrait, ProductTreeTrait}; | ||
| use crate::schema::csaf2_1::schema::CategoryOfTheBranch; | ||
| use crate::validation::ValidationError; | ||
|
|
||
| fn create_forbidden_strings_in_version_error( | ||
| product_name: &str, | ||
| forbidden_substring: &str, | ||
| product_path: &str, | ||
| ) -> ValidationError { | ||
| ValidationError { | ||
| message: format!( | ||
| "Product version '{}' contains forbidden substring '{}'", | ||
| product_name, forbidden_substring | ||
| ), | ||
| instance_path: format!("{}/name", product_path), | ||
| } | ||
| } | ||
|
|
||
| /// This order implicitly ensures that <= will be found before <, which will also match. | ||
| const FORBIDDEN_SUBSTRINGS: &[&str] = &["<=", "<", ">=", ">"]; | ||
| const FORBIDDEN_KEYWORDS: &[&str] = &["after", "all", "before", "earlier", "later", "prior", "versions"]; | ||
|
|
||
| /// 6.1.31 Version Range in Product Version | ||
| /// All branches with type `product_version` in the product tree must not contain any of the substrings | ||
| /// `<, <=, >, >=, after, all, before, earlier, later, prior, versions` in their branch `name`. | ||
| /// `<=` and `>=` are prioritized before `<` and `>` respectively. This only returns the first error, | ||
| /// i.e. `all versions before versions 4.x` would only throw an error for the `all` substring. | ||
| pub fn test_6_1_31_version_range_in_product_version_branch_name( | ||
| doc: &impl CsafTrait, | ||
| ) -> Result<(), Vec<ValidationError>> { | ||
| let mut errors: Option<Vec<ValidationError>> = None; | ||
| if let Some(product_tree) = doc.get_product_tree().as_ref() { | ||
| if let Some(branches) = product_tree.get_branches().as_ref() { | ||
| for (i, branch) in branches.iter().enumerate() { | ||
| branch.visit_branches_rec(&format!("/product_tree/branches/{}", i), &mut |branch, path| { | ||
| if branch.get_category() == &CategoryOfTheBranch::ProductVersion { | ||
| let branch_name = branch.get_name().to_lowercase(); | ||
| for forbidden in FORBIDDEN_SUBSTRINGS { | ||
| if branch_name.contains(forbidden) { | ||
| errors | ||
| .get_or_insert_with(Vec::new) | ||
| .push(create_forbidden_strings_in_version_error( | ||
| branch.get_name(), | ||
| forbidden, | ||
| path, | ||
| )); | ||
| break; | ||
| } | ||
| } | ||
| let product_name_tokenized = branch_name.split_whitespace().collect::<Vec<&str>>(); | ||
| for token in product_name_tokenized { | ||
| if FORBIDDEN_KEYWORDS.contains(&token) { | ||
| errors | ||
| .get_or_insert_with(Vec::new) | ||
| .push(create_forbidden_strings_in_version_error( | ||
| branch.get_name(), | ||
| token, | ||
| path, | ||
| )); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| errors.map_or(Ok(()), Err) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::test_helper::{run_csaf20_tests, run_csaf21_tests}; | ||
| use std::collections::HashMap; | ||
|
|
||
| #[test] | ||
| fn test_test_6_1_31() { | ||
| let errors = HashMap::from([ | ||
| ( | ||
| "01", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "prior to 4.2", | ||
| "prior", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "02", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "<4.2", | ||
| "<", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "03", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "<=4.1", | ||
| "<=", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "04", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "<= 4.1", | ||
| "<=", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "05", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "4.1 and earlier", | ||
| "earlier", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "06", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "all", | ||
| "all", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "07", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "before 4.2", | ||
| "before", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "08", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "4.2 and later", | ||
| "later", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ( | ||
| "09", | ||
| vec![create_forbidden_strings_in_version_error( | ||
| "3.X versions", | ||
| "versions", | ||
| "/product_tree/branches/0/branches/0/branches/0", | ||
| )], | ||
| ), | ||
| ]); | ||
| run_csaf20_tests( | ||
| "31", | ||
| test_6_1_31_version_range_in_product_version_branch_name, | ||
| errors.clone(), | ||
| ); | ||
| run_csaf21_tests("31", test_6_1_31_version_range_in_product_version_branch_name, errors); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.