Skip to content

Commit

Permalink
Added tests for naive filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekit2217 committed Jul 20, 2024
1 parent db17ce6 commit 0bbfeab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/filters/naive_filter/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,52 @@ mod tests {
assert_eq!(17, passed_messages);
assert_eq!(83, filtered_messages);
}

#[test]
fn invalid_filters() {
assert!(
NaiveFilter::from_filters(&vec!["method~='get]".to_string()]).is_err(),
"The filter should not have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["method~='get']".to_string()]).is_err(),
"The filter should not have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status~=`404".to_string()]).is_err(),
"The filter should not have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status~=`404,123`".to_string()]).is_err(),
"The filter should not have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status~=`abc`".to_string()]).is_err(),
"The filter should not have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status~=`abc`".to_string()]).is_err(),
"The filter should not have been created"
);
}

#[test]
fn valid_filters() {
assert!(
NaiveFilter::from_filters(&vec!["method=='get'".to_string()]).is_ok(),
"The filter should have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status==`404`".to_string()]).is_ok(),
"The filter should have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["status==internal.status".to_string()]).is_ok(),
"The filter should have been created"
);
assert!(
NaiveFilter::from_filters(&vec!["internal.value!=`3.1415962`".to_string()]).is_ok(),
"The filter should not have been created"
);
}
}
1 change: 1 addition & 0 deletions src/filters/naive_filter/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl NaiveFilterOperand {
}

pub(crate) fn from_str(operand_str: &str) -> Result<Self, NaiveFilterError> {
let operand_str = operand_str.trim();
match operand_str.chars().next() {
// number
Some('`') => {
Expand Down

0 comments on commit 0bbfeab

Please sign in to comment.