Skip to content
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
2 changes: 1 addition & 1 deletion src/assertions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl AssertionChecker {
"file-contains" => {
let file = check.command.file.as_ref().ok_or("Missing file")?;
let contains = check.command.contains.as_ref().ok_or("Missing contains")?;
file::check_file_content(&self.work_dir, file, contains, false)
file::check_file_content(&self.work_dir, file, contains, true)
}
"log-contains" => {
let pattern = check.command.pattern.as_ref().ok_or("Missing pattern")?;
Expand Down
48 changes: 48 additions & 0 deletions src/assertions/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#[cfg(test)]
mod tests {
use crate::assertions::AssertionChecker;
use crate::models::check::CheckData;
use std::path::Path;

fn create_checker(log_file: &str) -> AssertionChecker {
Expand Down Expand Up @@ -260,4 +261,51 @@ mod tests {
"nonexistent log should produce empty data"
);
}

#[test]
fn test_file_contains_via_evaluate_check() {
let work_dir = tempfile::tempdir().unwrap();
let test_file = work_dir.path().join("report.md");
std::fs::write(&test_file, "Screened patents: 42").unwrap();

let empty_log = work_dir.path().join("empty.log");
std::fs::write(&empty_log, "").unwrap();

let checker = AssertionChecker::new(&empty_log, work_dir.path(), None);

let check = crate::models::CheckStep {
name: "contains_patent_data".to_string(),
command: CheckData {
command: "file-contains".to_string(),
file: Some("report.md".to_string()),
contains: Some("Screened patents".to_string()),
..Default::default()
},
deny: false,
};

let result = checker.evaluate_check(&check);
assert!(
result.is_ok(),
"file-contains should pass when string is present"
);

// String not in file should fail
let check_missing = crate::models::CheckStep {
name: "contains_missing".to_string(),
command: CheckData {
command: "file-contains".to_string(),
file: Some("report.md".to_string()),
contains: Some("NOTPRESENT".to_string()),
..Default::default()
},
deny: false,
};

let result = checker.evaluate_check(&check_missing);
assert!(
result.is_err(),
"file-contains should fail when string is absent"
);
}
}
2 changes: 1 addition & 1 deletion src/models/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CheckStep {
}

/// Check data - command type and arguments
#[derive(Debug, Clone, Deserialize, Serialize)]
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct CheckData {
pub command: String,
#[serde(default)]
Expand Down
Loading